From 28d2271cac208d528e34042d0776897a36ddcd10 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 9 Jul 2016 22:14:17 +0200 Subject: [PATCH] doc: add `added:` information for cluster Ref: https://github.com/nodejs/node/issues/6578 PR-URL: https://github.com/nodejs/node/pull/7640 Reviewed-By: James M Snell Reviewed-By: Colin Ihrig --- doc/api/cluster.md | 91 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/doc/api/cluster.md b/doc/api/cluster.md index 3bdc8756b1b68e..0c34aae6b76939 100644 --- a/doc/api/cluster.md +++ b/doc/api/cluster.md @@ -108,12 +108,18 @@ responsibility to manage the worker pool for your application's needs. ## Class: Worker + A Worker object contains all public information and method about a worker. In the master it can be obtained using `cluster.workers`. In a worker it can be obtained using `cluster.worker`. ### Event: 'disconnect' + Similar to the `cluster.on('disconnect')` event, but specific to this worker. @@ -124,12 +130,18 @@ cluster.fork().on('disconnect', () => { ``` ### Event: 'error' + This event is the same as the one provided by [`child_process.fork()`][]. In a worker you can also use `process.on('error')`. ### Event: 'exit' + * `code` {Number} the exit code, if it exited normally. * `signal` {String} the name of the signal (eg. `'SIGHUP'`) that caused @@ -151,6 +163,9 @@ worker.on('exit', (code, signal) => { ``` ### Event: 'listening' + * `address` {Object} @@ -165,6 +180,9 @@ cluster.fork().on('listening', (address) => { It is not emitted in the worker. ### Event: 'message' + * `message` {Object} * `handle` {undefined|Object} @@ -220,6 +238,9 @@ if (cluster.isMaster) { ``` ### Event: 'online' + Similar to the `cluster.on('online')` event, but specific to this worker. @@ -232,6 +253,9 @@ cluster.fork().on('online', () => { It is not emitted in the worker. ### worker.disconnect() + In a worker, this function will close all servers, wait for the `'close'` event on those servers, and then disconnect the IPC channel. @@ -293,6 +317,9 @@ if (cluster.isMaster) { ``` ### worker.id + * {Number} @@ -303,17 +330,26 @@ While a worker is alive, this is the key that indexes it in cluster.workers ### worker.isConnected() + This function returns `true` if the worker is connected to its master via its IPC channel, `false` otherwise. A worker is connected to its master after it's been created. It is disconnected after the `'disconnect'` event is emitted. ### worker.isDead() + This function returns `true` if the worker's process has terminated (either because of exiting or being signaled). Otherwise, it returns `false`. ### worker.kill([signal='SIGTERM']) + * `signal` {String} Name of the kill signal to send to the worker process. @@ -330,6 +366,9 @@ Note that in a worker, `process.kill()` exists, but it is not this function, it is [`kill`][]. ### worker.process + * {ChildProcess} @@ -344,6 +383,9 @@ on `process` and `.suicide` is not `true`. This protects against accidental disconnection. ### worker.send(message[, sendHandle][, callback]) + * `message` {Object} * `sendHandle` {Handle} @@ -373,6 +415,10 @@ if (cluster.isMaster) { ``` ### worker.suicide + * {Boolean} @@ -393,6 +439,9 @@ worker.kill(); ``` ## Event: 'disconnect' + * `worker` {cluster.Worker} @@ -411,6 +460,9 @@ cluster.on('disconnect', (worker) => { ``` ## Event: 'exit' + * `worker` {cluster.Worker} * `code` {Number} the exit code, if it exited normally. @@ -432,6 +484,9 @@ cluster.on('exit', (worker, code, signal) => { See [child_process event: 'exit'][]. ## Event: 'fork' + * `worker` {cluster.Worker} @@ -457,6 +512,9 @@ cluster.on('exit', (worker, code, signal) => { ``` ## Event: 'listening' + * `worker` {cluster.Worker} * `address` {Object} @@ -493,6 +551,9 @@ Emitted when the cluster master receives a message from any worker. See [child_process event: 'message'][]. ## Event: 'online' + * `worker` {cluster.Worker} @@ -508,6 +569,9 @@ cluster.on('online', (worker) => { ``` ## Event: 'setup' + * `settings` {Object} @@ -520,6 +584,9 @@ The `settings` object is the `cluster.settings` object at the time If accuracy is important, use `cluster.settings`. ## cluster.disconnect([callback]) + * `callback` {Function} called when all workers are disconnected and handles are closed @@ -534,6 +601,9 @@ The method takes an optional callback argument which will be called when finishe This can only be called from the master process. ## cluster.fork([env]) + * `env` {Object} Key/value pairs to add to worker process environment. * return {cluster.Worker} @@ -543,6 +613,9 @@ Spawn a new worker process. This can only be called from the master process. ## cluster.isMaster + * {Boolean} @@ -551,12 +624,18 @@ by the `process.env.NODE_UNIQUE_ID`. If `process.env.NODE_UNIQUE_ID` is undefined, then `isMaster` is `true`. ## cluster.isWorker + * {Boolean} True if the process is not a master (it is the negation of `cluster.isMaster`). ## cluster.schedulingPolicy + The scheduling policy, either `cluster.SCHED_RR` for round-robin or `cluster.SCHED_NONE` to leave it to the operating system. This is a @@ -572,6 +651,9 @@ distribute IOCP handles without incurring a large performance hit. values are `"rr"` and `"none"`. ## cluster.settings + * {Object} * `execArgv` {Array} list of string arguments passed to the Node.js @@ -590,6 +672,9 @@ the settings, including the default values. This object is not supposed to be changed or set manually, by you. ## cluster.setupMaster([settings]) + * `settings` {Object} * `exec` {String} file path to worker file. (Default=`process.argv[1]`) @@ -630,6 +715,9 @@ cluster.fork(); // http worker This can only be called from the master process. ## cluster.worker + * {Object} @@ -648,6 +736,9 @@ if (cluster.isMaster) { ``` ## cluster.workers + * {Object}