From 1f05a0559513a19a0782563496d7c21c2a4520d0 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 25 Oct 2015 11:48:41 -0700 Subject: [PATCH] lib,doc: return boolean from child.send() The documentation indicates that child.send() returns a boolean but it has returned undefinined at since v0.12.0. It now returns a boolean per the (slightly updated) documentation. PR-URL: https://github.com/nodejs/node/pull/3516 Reviewed-By: Ben Noordhuis --- lib/internal/child_process.js | 6 +++--- test/parallel/test-child-process-send-returns-boolean.js | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 test/parallel/test-child-process-send-returns-boolean.js diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js index 3613bfd0efeec8..c81697546cebd4 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -504,8 +504,7 @@ function setupChannel(target, channel) { handle = undefined; } if (this.connected) { - this._send(message, handle, false, callback); - return; + return this._send(message, handle, false, callback); } const ex = new Error('channel closed'); if (typeof callback === 'function') { @@ -513,6 +512,7 @@ function setupChannel(target, channel) { } else { this.emit('error', ex); // FIXME(bnoordhuis) Defer to next tick. } + return false; }; target._send = function(message, handle, swallowErrors, callback) { @@ -577,7 +577,7 @@ function setupChannel(target, channel) { handle: null, message: message, }); - return; + return this._handleQueue.length === 1; } var req = new WriteWrap(); diff --git a/test/parallel/test-child-process-send-returns-boolean.js b/test/parallel/test-child-process-send-returns-boolean.js new file mode 100644 index 00000000000000..b751846947822c --- /dev/null +++ b/test/parallel/test-child-process-send-returns-boolean.js @@ -0,0 +1,9 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const fork = require('child_process').fork; + +const n = fork(common.fixturesDir + '/empty.js'); + +const rv = n.send({ hello: 'world' }); +assert.strictEqual(rv, true);