Skip to content

Commit

Permalink
doc: document the return value of {process,worker}.send()
Browse files Browse the repository at this point in the history
Add documentation for the boolean value returned by process.send()
and worker.send().

Fixes: nodejs#26995
  • Loading branch information
shree-y committed May 24, 2019
1 parent 782e702 commit 9426474
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
14 changes: 12 additions & 2 deletions doc/api/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,16 @@ if (cluster.isMaster) {
}
```

`worker.send()` will return `false` if the channel has closed or when the
The optional `callback` is a function that is invoked after the message is
sent but before the worker or master may have received it. The function is called with a
single argument: `null` on success, or an [`Error`][] object on failure.

If no `callback` function is provided and the message cannot be sent, an
`'error'` event will be emitted by the [`Worker`][] object. This can
happen, for instance, when the worker has already exited.


`worker.send()` will throw an error if the channel has closed or when the
backlog of unsent messages exceeds a threshold that makes it unwise to send
more. Otherwise, the method returns `true`. The `callback` function can be
used to implement flow control.
Expand Down Expand Up @@ -845,7 +854,8 @@ socket.on('data', (id) => {
const worker = cluster.workers[id];
});
```

[`Worker`]: #cluster_class_worker
[`Error`]: errors.html#errors_class_error
[`ChildProcess.send()`]: child_process.html#child_process_subprocess_send_message_sendhandle_options_callback
[`child_process.fork()`]: child_process.html#child_process_child_process_fork_modulepath_args_options
[`child_process` event: `'exit'`]: child_process.html#child_process_event_exit
Expand Down
12 changes: 11 additions & 1 deletion doc/api/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -1840,7 +1840,16 @@ If Node.js was not spawned with an IPC channel, `process.send()` will be
The message goes through serialization and parsing. The resulting message might
not be the same as what is originally sent.

`process.send()` will return `false` if the channel has closed or when the
The optional `callback` is a function that is invoked after the message is
sent but before the parent process may have received it. The function is called with a
single argument: `null` on success, or an [`Error`][] object on failure.

If no `callback` function is provided and the message cannot be sent, an
`'error'` event will be emitted by the [`Process`][] object. This can
happen, for instance, when the process has already exited.


`process.send()` will return false if the channel has closed or when the
backlog of unsent messages exceeds a threshold that makes it unwise to send
more. Otherwise, the method returns `true`. The `callback` function can be
used to implement flow control.
Expand Down Expand Up @@ -2340,3 +2349,4 @@ cases:
[process_emit_warning]: #process_process_emitwarning_warning_type_code_ctor
[process_warning]: #process_event_warning
[report documentation]: report.html
[`Process`]: #process_process

0 comments on commit 9426474

Please sign in to comment.