Skip to content

Commit

Permalink
lib,doc: return boolean from child.send()
Browse files Browse the repository at this point in the history
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: nodejs#3516
Reviewed-By: Ben Noordhuis <[email protected]>
  • Loading branch information
Trott authored and Myles Borins committed Jul 14, 2016
1 parent 63d94ee commit 1f05a05
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/internal/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,15 +504,15 @@ 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') {
process.nextTick(callback, ex);
} else {
this.emit('error', ex); // FIXME(bnoordhuis) Defer to next tick.
}
return false;
};

target._send = function(message, handle, swallowErrors, callback) {
Expand Down Expand Up @@ -577,7 +577,7 @@ function setupChannel(target, channel) {
handle: null,
message: message,
});
return;
return this._handleQueue.length === 1;
}

var req = new WriteWrap();
Expand Down
9 changes: 9 additions & 0 deletions test/parallel/test-child-process-send-returns-boolean.js
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 1f05a05

Please sign in to comment.