child_process: add callback parameter to .send()
authorBen Noordhuis <info@bnoordhuis.nl>
Sun, 30 Aug 2015 22:49:34 +0000 (00:49 +0200)
committerRod Vagg <rod@vagg.org>
Sun, 6 Sep 2015 11:38:58 +0000 (21:38 +1000)
commitd010568c237ada3fa0673fb14d6714c196f922a2
treefa4587e0cecfb07382fa8f88578bac1c1da176fa
parent5201cb0ff188fd68ba66fcc75489379c8dd1d274
child_process: add callback parameter to .send()

Add an optional callback parameter to `ChildProcess.prototype.send()`
that is invoked when the message has been sent.

Juggle the control channel's reference count so that in-flight messages
keep the event loop (and therefore the process) alive until they have
been sent.

`ChildProcess.prototype.send()` and `process.send()` used to operate
synchronously but became asynchronous in commit libuv/libuv@393c1c5
("unix: set non-block mode in uv_{pipe,tcp,udp}_open"), which landed
in io.js in commit 07bd05b ("deps: update libuv to 1.2.1").

Fixes: https://github.com/nodejs/node/issues/760
PR-URL: https://github.com/nodejs/node/pull/2620
Reviewed-By: trevnorris - Trevor Norris <trev.norris@gmail.com>
Reviewed-By: jasnell - James M Snell <jasnell@gmail.com>
doc/api/child_process.markdown
doc/api/cluster.markdown
lib/child_process.js
lib/internal/child_process.js
test/parallel/test-child-process-send-cb.js [new file with mode: 0644]