#1314 Env.addShutdownHook

yachris Sat 13 Nov 2010

Hello,

Two questions, I guess. First, any way to catch interrupts? It'd be nice to be able to do some shutdown things in the event of a ctrl-c or the equivalent.

Alternatively, I'd like to be able to see if there is a keypress waiting (something like InStream#peek) but without blocking.

Thanks!

brian Sat 13 Nov 2010

Promoted to ticket #1314 and assigned to brian

Regarding interupts, about the best we can do is wrap Java's Runtime.addShutdownHook as a new API on Env. So I will definitely do that.

Regarding the peeking at stdin - can you even do that in Java? Java's IO classes really just have available, and I've found that method is pretty poorly implemented across the board. But I suppose if Java's System.in supports it we could do something special in Fantom's IO classes.

brian Mon 3 Jan 2011

Renamed from Interrupts/non-blocking keyboard watching to Env.addShutdownHook

brian Mon 3 Jan 2011

Ticket resolved in 1.0.57

Added two new methods to sys::Env for adding/removing shutdown hooks:

**
** Add a function to be called on VM shutdown.  Throw
** NotImmutableErr if the function is not immutable.
** Default implementation delegates to `parent`.
**
virtual Void addShutdownHook(|->| hook)

**
** Remove a shutdown hook function which was added
** by `addShutdownHook`.  Remove true if hook had been
** previously added and was unregistered, false otherwise.
** Default implementation delegates to `parent`.
**
virtual Bool removeShutdownHook(|->| hook)

yachris Tue 4 Jan 2011

Thanks!

Akcelisto Wed 5 Jan 2011

There is method sys::Env.exit. May be better name addExitHook?

brian Wed 5 Jan 2011

Well shutdown isn't necessarily because exit is called, could also be a signal handler triggered. So I copied Java's terms.

Although exit is a bit shorter and makes just as much sense.

Any other votes for addExitHook? You have about two hours before I kick off the build in which case it is staying the way it is.

Login or Signup to reply.