summaryrefslogtreecommitdiff
path: root/test/parallel/test-child-process-send-cb.js
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2015-08-31 00:49:34 +0200
committerRod Vagg <rod@vagg.org>2015-09-06 21:37:58 +1000
commit607aa3ac82cb8c07487b474e548aa205e8ee3ca5 (patch)
tree1fbec11132329be21f81e4fa59e463fe6e102f63 /test/parallel/test-child-process-send-cb.js
parent599d4f5f3a21a475b20e69057a07c87b790c4214 (diff)
downloadandroid-node-v8-607aa3ac82cb8c07487b474e548aa205e8ee3ca5.tar.gz
android-node-v8-607aa3ac82cb8c07487b474e548aa205e8ee3ca5.tar.bz2
android-node-v8-607aa3ac82cb8c07487b474e548aa205e8ee3ca5.zip
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>
Diffstat (limited to 'test/parallel/test-child-process-send-cb.js')
-rw-r--r--test/parallel/test-child-process-send-cb.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/parallel/test-child-process-send-cb.js b/test/parallel/test-child-process-send-cb.js
new file mode 100644
index 0000000000..d65a1abd20
--- /dev/null
+++ b/test/parallel/test-child-process-send-cb.js
@@ -0,0 +1,19 @@
+'use strict';
+const common = require('../common');
+const assert = require('assert');
+const fork = require('child_process').fork;
+
+if (process.argv[2] === 'child') {
+ process.send('ok', common.mustCall(function(err) {
+ assert.strictEqual(err, null);
+ }));
+} else {
+ const child = fork(process.argv[1], ['child']);
+ child.on('message', common.mustCall(function(message) {
+ assert.strictEqual(message, 'ok');
+ }));
+ child.on('exit', common.mustCall(function(exitCode, signalCode) {
+ assert.strictEqual(exitCode, 0);
+ assert.strictEqual(signalCode, null);
+ }));
+}