Skip to content

Commit f236b3a

Browse files
Trottrvagg
authored andcommitted
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: #3516 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent b8cea49 commit f236b3a

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

doc/api/child_process.markdown

+3-2
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,10 @@ argument: `null` on success, or an `Error` object on failure.
266266
`child.send()` emits an `'error'` event if no callback was given and the message
267267
cannot be sent, for example because the child process has already exited.
268268

269-
Returns `true` under normal circumstances or `false` when the backlog of
269+
`child.send()` returns `false` if the channel has closed or when the backlog of
270270
unsent messages exceeds a threshold that makes it unwise to send more.
271-
Use the callback mechanism to implement flow control.
271+
Otherwise, it returns `true`. Use the callback mechanism to implement flow
272+
control.
272273

273274
#### Example: sending server object
274275

lib/internal/child_process.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -504,15 +504,15 @@ function setupChannel(target, channel) {
504504
handle = undefined;
505505
}
506506
if (this.connected) {
507-
this._send(message, handle, false, callback);
508-
return;
507+
return this._send(message, handle, false, callback);
509508
}
510509
const ex = new Error('channel closed');
511510
if (typeof callback === 'function') {
512511
process.nextTick(callback, ex);
513512
} else {
514513
this.emit('error', ex); // FIXME(bnoordhuis) Defer to next tick.
515514
}
515+
return false;
516516
};
517517

518518
target._send = function(message, handle, swallowErrors, callback) {
@@ -577,7 +577,7 @@ function setupChannel(target, channel) {
577577
handle: null,
578578
message: message,
579579
});
580-
return;
580+
return this._handleQueue.length === 1;
581581
}
582582

583583
var req = new WriteWrap();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const fork = require('child_process').fork;
5+
6+
const n = fork(common.fixturesDir + '/empty.js');
7+
8+
const rv = n.send({ hello: 'world' });
9+
assert.strictEqual(rv, true);

0 commit comments

Comments
 (0)