Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f236b3a

Browse filesBrowse 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 <info@bnoordhuis.nl>
1 parent b8cea49 commit f236b3a
Copy full SHA for f236b3a

File tree

Expand file treeCollapse file tree

3 files changed

+15
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+15
-5
lines changed
Open diff view settings
Collapse file

‎doc/api/child_process.markdown‎

Copy file name to clipboardExpand all lines: doc/api/child_process.markdown
+3-2Lines changed: 3 additions & 2 deletions
  • Display the source diff
  • Display the rich diff
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

Collapse file

‎lib/internal/child_process.js‎

Copy file name to clipboardExpand all lines: lib/internal/child_process.js
+3-3Lines changed: 3 additions & 3 deletions
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();
Collapse file
+9Lines changed: 9 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.