diff options
author | Timothy J Fontaine <tjfontaine@gmail.com> | 2013-12-31 14:48:20 -0800 |
---|---|---|
committer | Timothy J Fontaine <tjfontaine@gmail.com> | 2013-12-31 14:48:20 -0800 |
commit | ffb718b5a36302d98dac1fef683600e621560255 (patch) | |
tree | 5db2c1dedd3190514a94c022bb001ac33c6eaf1d | |
parent | 3917232030ec3b096fa08bb03b0bdc82301c0ac0 (diff) | |
download | node-ffb718b5a36302d98dac1fef683600e621560255.tar.gz |
doc: clarify process on exit safe usage
-rw-r--r-- | doc/api/process.markdown | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/doc/api/process.markdown b/doc/api/process.markdown index 980254e6c..b2f43ded7 100644 --- a/doc/api/process.markdown +++ b/doc/api/process.markdown @@ -8,15 +8,17 @@ It is an instance of [EventEmitter][]. ## Event: 'exit' -Emitted when the process is about to exit. This is a good hook to perform -constant time checks of the module's state (like for unit tests). The main -event loop will no longer be run after the 'exit' callback finishes, so -timers may not be scheduled. The callback takes one argument, the code the -process is exiting with. +Emitted when the process is about to exit. There is no way to prevent the +exiting of the event loop at this point, and once all `exit` listeners have +finished running the process will exit. Therefore you **must** only perform +**synchronous** operations in this handler. This is a good hook to perform +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`: process.on('exit', function(code) { + // do *NOT* do this setTimeout(function() { console.log('This will not run'); }, 0); |