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 <info@bnoordhuis.nl>
This commit is contained in:
Rich Trott 2015-10-25 11:48:41 -07:00
parent 9f967058e8
commit cdcf00a0b9
3 changed files with 15 additions and 5 deletions

View File

@ -266,9 +266,10 @@ argument: `null` on success, or an `Error` object on failure.
`child.send()` emits an `'error'` event if no callback was given and the message `child.send()` emits an `'error'` event if no callback was given and the message
cannot be sent, for example because the child process has already exited. cannot be sent, for example because the child process has already exited.
Returns `true` under normal circumstances or `false` when the backlog of `child.send()` returns `false` if the channel has closed or when the backlog of
unsent messages exceeds a threshold that makes it unwise to send more. unsent messages exceeds a threshold that makes it unwise to send more.
Use the callback mechanism to implement flow control. Otherwise, it returns `true`. Use the callback mechanism to implement flow
control.
#### Example: sending server object #### Example: sending server object

View File

@ -504,8 +504,7 @@ function setupChannel(target, channel) {
handle = undefined; handle = undefined;
} }
if (this.connected) { if (this.connected) {
this._send(message, handle, false, callback); return this._send(message, handle, false, callback);
return;
} }
const ex = new Error('channel closed'); const ex = new Error('channel closed');
if (typeof callback === 'function') { if (typeof callback === 'function') {
@ -513,6 +512,7 @@ function setupChannel(target, channel) {
} else { } else {
this.emit('error', ex); // FIXME(bnoordhuis) Defer to next tick. this.emit('error', ex); // FIXME(bnoordhuis) Defer to next tick.
} }
return false;
}; };
target._send = function(message, handle, swallowErrors, callback) { target._send = function(message, handle, swallowErrors, callback) {
@ -577,7 +577,7 @@ function setupChannel(target, channel) {
handle: null, handle: null,
message: message, message: message,
}); });
return; return this._handleQueue.length === 1;
} }
var req = new WriteWrap(); var req = new WriteWrap();

View File

@ -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);