Skip to content

Commit 432cce6

Browse files
sam-githubrvagg
authored andcommitted
doc: describe process API for IPC
Reviewed-By: Ben Noordhuis <[email protected]> PR-URL: #1978
1 parent 779e14f commit 432cce6

File tree

3 files changed

+54
-4
lines changed

3 files changed

+54
-4
lines changed

doc/api/child_process.markdown

+6-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ you are listening on both events to fire a function, remember to guard against
4646
calling your function twice.
4747

4848
See also [`ChildProcess#kill()`](#child_process_child_kill_signal) and
49-
[`ChildProcess#send()`](#child_process_child_send_message_sendhandle).
49+
[`ChildProcess#send()`](#child_process_child_send_message_sendhandle_callback).
5050

5151
### Event: 'exit'
5252

@@ -85,8 +85,9 @@ and the `.connected` property is false.
8585

8686
### Event: 'message'
8787

88-
* `message` {Object} a parsed JSON object or primitive value
89-
* `sendHandle` {Handle object} a Socket or Server object
88+
* `message` {Object} a parsed JSON object or primitive value.
89+
* `sendHandle` {Handle object} a [net.Socket][] or [net.Server][] object, or
90+
undefined.
9091

9192
Messages sent by `.send(message, [sendHandle])` are obtained using the
9293
`message` event.
@@ -760,3 +761,5 @@ throw. The `Error` object will contain the entire result from
760761
[`child_process.spawnSync`](#child_process_child_process_spawnsync_command_args_options)
761762

762763
[EventEmitter]: events.html#events_class_events_eventemitter
764+
[net.Server]: net.html#net_class_net_server
765+
[net.Socket]: net.html#net_class_net_socket

doc/api/cluster.markdown

+3-1
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ exit, the master may choose not to respawn a worker based on this value.
436436
Send a message to a worker or master, optionally with a handle.
437437

438438
In the master this sends a message to a specific worker. It is identical to
439-
[child.send()](child_process.html#child_process_child_send_message_sendhandle).
439+
[ChildProcess.send()][].
440440

441441
In a worker this sends a message to the master. It is identical to
442442
`process.send()`.
@@ -646,3 +646,5 @@ Similar to the `cluster.on('exit')` event, but specific to this worker.
646646
This event is the same as the one provided by `child_process.fork()`.
647647

648648
In a worker you can also use `process.on('error')`.
649+
650+
[ChildProcess.send()]: child_process.html#child_process_child_send_message_sendhandle_callback

doc/api/process.markdown

+45
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ Example of listening for `exit`:
7070
});
7171

7272

73+
## Event: 'message'
74+
75+
* `message` {Object} a parsed JSON object or primitive value
76+
* `sendHandle` {Handle object} a [net.Socket][] or [net.Server][] object, or
77+
undefined.
78+
79+
Messages sent by [ChildProcess.send()][] are obtained using the `'message'`
80+
event on the child's process object.
81+
82+
7383
## Event: 'beforeExit'
7484

7585
This event is emitted when Node.js empties its event loop and has nothing else to
@@ -904,6 +914,38 @@ a diff reading, useful for benchmarks and measuring intervals:
904914
}, 1000);
905915

906916

917+
## process.send(message[, sendHandle][, callback])
918+
919+
* `message` {Object}
920+
* `sendHandle` {Handle object}
921+
922+
When Node.js is spawned with an IPC channel attached, it can send messages to its
923+
parent process using `process.send()`. Each will be received as a
924+
['message'](child_process.html#child_process_event_message)
925+
event on the parent's `ChildProcess` object.
926+
927+
If io.js was not spawned with an IPC channel, `process.send()` will be undefined.
928+
929+
930+
## process.disconnect()
931+
932+
Close the IPC channel to the parent process, allowing this child to exit
933+
gracefully once there are no other connections keeping it alive.
934+
935+
Identical to the parent process's
936+
[ChildProcess.disconnect()](child_process.html#child_process_child_disconnect).
937+
938+
If io.js was not spawned with an IPC channel, `process.disconnect()` will be
939+
undefined.
940+
941+
942+
### process.connected
943+
944+
* {Boolean} Set to false after `process.disconnect()` is called
945+
946+
If `process.connected` is false, it is no longer possible to send messages.
947+
948+
907949
## process.mainModule
908950

909951
Alternate way to retrieve
@@ -915,4 +957,7 @@ to the same module.
915957

916958
As with `require.main`, it will be `undefined` if there was no entry script.
917959

960+
[ChildProcess.send()]: child_process.html#child_process_child_send_message_sendhandle_callback
918961
[EventEmitter]: events.html#events_class_events_eventemitter
962+
[net.Server]: net.html#net_class_net_server
963+
[net.Socket]: net.html#net_class_net_socket

0 commit comments

Comments
 (0)