From f17b76afa4082808919a554293fa03fa6fd7f0f0 Mon Sep 17 00:00:00 2001
From: Ryan node.exit(code)
ARGV
stdout
,
+ stderr
, and
+ stdin
+ node.fs.File
. (See below)Timers
@@ -976,24 +989,34 @@ exports.assertEquals = function (expected, found, name_opt) {
to the file calling include()
.
Alternatively one can use HTTP URLs to load modules. For example, + +
include("http://tinyclouds.org/node/mjsunit.js");+
include()
inserts the exported objects from the
specified module into the global namespace.
onLoad
- Because file loading does not happen instantaneously, and
- because Node has a policy of never blocking, the callback
- onLoad
can be set and will notify the user when the
+ Because module loading does not happen instantaneously, and
+ because Node has a policy of never blocking, a callback
+ onLoad
can be set that will notify the user when the
included modules are loaded. Each file/module can have an
onLoad
callback.
To export an object, add to the special exports
- object. The functions fail
and
+ object.
+ The functions fail
and
deepEquals
are not exported and remain private to
the module.
+
+ Alternatively, one can use this
instead of
+ exports
.
@@ -1010,20 +1033,37 @@ function onLoad () {
include()
and require()
cannot be
- used after onLoad()
is called. So put them at the
- beginning of your file.
+ used after onLoad()
is called.
onExit
- Additionally when node.exit()
is called or when
- a program exits naturally, the function onExit()
will be
+ When the program exits a callback onExit()
will be
called for each module (children first).
+
The onExit()
callback cannot perform I/O as the process is
going to forcably exit in several microseconds, however it is a good
hook to perform some constant time checks of the module's state.
It's useful for unit tests.
+include("mjsunit.js"); + +var timer_executed = false; + +setTimeout(function () { + timer_executed = true +}, 1000); + +function onExit () { + assertTrue(timer_executed); +} ++
Just to reiterate: onExit()
, is not the place to close
files or shutdown servers. The process will exit before they get