joyent/node — Issue #2578: feature request: allow process' exit event handler to schedule future work
Author: csosborn
Created: 2012-01-18 23:51:19+00:00
State: open

Adding an 'exit' event handler to `process` works well as a way to find out that node is about to exit, but I don't understand why its handler cannot schedule new asynchronous events (for instance, set a timeout) and thus keep Node alive.

It would be useful for me, while unit testing, to detect when the code under test has allowed the event loop to end. The only way I can do that is with a process exit handler, but by then it is too late to do anything asynchronous, so my test runner has no choice but to spit out an error and die. If it doesn't make sense to change the existing behavior, would it be possible to have a new event that indicates Node event loop exhaustion? In this case Node would fire the new event first, then only begin the exit sequence if the event loop is still empty.