include("asserts.js"); - -var timer_executed = false; - -setTimeout(function () { - timer_executed = true -}, 1000); - -process.addListener("exit", function () { - assertTrue(timer_executed); -});-
diff --git a/benchmark/process_loop.js b/benchmark/process_loop.js index ec971f0959..2e1e35465a 100644 --- a/benchmark/process_loop.js +++ b/benchmark/process_loop.js @@ -11,7 +11,7 @@ function next (i) { }); child.addListener("exit", function (code) { - if (code != 0) node.exit(-1); + if (code != 0) process.exit(-1); next(i - 1); }); } diff --git a/doc/api.html b/doc/api.html index b396955dbd..80feec48d7 100644 --- a/doc/api.html +++ b/doc/api.html @@ -61,18 +61,10 @@ of the 16bit javascript string characters. Both are relatively fast—use them if you can. "utf8" is slower and should be avoided when possible.
Unless otherwise noted, functions are all asynchronous and do not block execution.
These objects are available to all programs.
-Immediately ends the process with the specified code. -
--An array containing the command line arguments. +The filename of the script being executed.
process is the equivalent of window in browser-side javascript. It is +the global scope. process is an instance of node.EventEmitter.
Event | +Parameters | +Notes | +
---|---|---|
"exit" |
+code |
+Made when the process exits.
+ A listener on this event should not try to perform
+ I/O since the process will forcibly exit in less
+ than microsecond. However, it is a good hook to
+ perform constant time checks of the module’s
+ state (like for unit tests).
+ |
+
-An object containing the user environment. See environ(7). +Ends the process with the specified code. By default it exits with the +success code 0.
-The filename of the script being executed. +An array containing the command line arguments.
-A special global object. The process object is like the window object of -browser-side javascript. +An object containing the user environment. See environ(7).
(Functions require_async() and include_async() also exist.)
When the program exits a special object called process will emit an -"exit" event.
The "exit" event cannot perform I/O since the process is going to -forcibly exit in less than microsecond. However, it is a good hook to -perform constant time checks of the module’s state. E.G. for unit tests:
include("asserts.js"); - -var timer_executed = false; - -setTimeout(function () { - timer_executed = true -}, 1000); - -process.addListener("exit", function () { - assertTrue(timer_executed); -});-
Just to reiterate: the "exit" event, is not the place to close files or -shutdown servers. The process will exit before they get performed.