|
@ -8,15 +8,17 @@ It is an instance of [EventEmitter][]. |
|
|
|
|
|
|
|
|
## Event: 'exit' |
|
|
## Event: 'exit' |
|
|
|
|
|
|
|
|
Emitted when the process is about to exit. This is a good hook to perform |
|
|
Emitted when the process is about to exit. There is no way to prevent the |
|
|
constant time checks of the module's state (like for unit tests). The main |
|
|
exiting of the event loop at this point, and once all `exit` listeners have |
|
|
event loop will no longer be run after the 'exit' callback finishes, so |
|
|
finished running the process will exit. Therefore you **must** only perform |
|
|
timers may not be scheduled. The callback takes one argument, the code the |
|
|
**synchronous** operations in this handler. This is a good hook to perform |
|
|
process is exiting with. |
|
|
checks on the module's state (like for unit tests). The callback takes one |
|
|
|
|
|
argument, the code the process is exiting with. |
|
|
|
|
|
|
|
|
Example of listening for `exit`: |
|
|
Example of listening for `exit`: |
|
|
|
|
|
|
|
|
process.on('exit', function(code) { |
|
|
process.on('exit', function(code) { |
|
|
|
|
|
// do *NOT* do this |
|
|
setTimeout(function() { |
|
|
setTimeout(function() { |
|
|
console.log('This will not run'); |
|
|
console.log('This will not run'); |
|
|
}, 0); |
|
|
}, 0); |
|
|