From f17b76afa4082808919a554293fa03fa6fd7f0f0 Mon Sep 17 00:00:00 2001 From: Ryan Date: Sun, 21 Jun 2009 23:27:36 +0200 Subject: [PATCH] Fix up docs. --- website/api.html | 58 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/website/api.html b/website/api.html index 3b3bcdbaf5..7b8236962b 100644 --- a/website/api.html +++ b/website/api.html @@ -47,7 +47,11 @@ -
  • Modules
  • +
  • Modules +
      +
    1. onLoad
    2. +
    3. onExit
    4. +
    @@ -104,6 +108,15 @@
    node.exit(code)
    Immediately ends the process with the specified code.
    + +
    ARGV
    +
    An array containing the command line arguments.
    + +
    stdout, + stderr, and + stdin +
    +
    Objects of type 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