include("asserts.js"); - -var timer_executed = false; - -setTimeout(function () { - timer_executed = true -}, 1000); - -process.addListener("exit", function () { - assertTrue(timer_executed); -});-
From 23c7f472d066087d8053e31e3797a91053a79d9a Mon Sep 17 00:00:00 2001
From: Ryan Dahl
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.