-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Adding Core support for Promises #5020
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
c1613c0
a8efd4f
4af7ec2
0e0a2d9
8798a26
355205b
7b8e57d
3f2b0d8
23ba073
68837b8
3317652
846bd49
d90b42c
adbe352
697ce01
f36b62d
082fa08
54e3001
014fb3e
15a42c1
8586b10
40ca55e
3928beb
fa725b3
0528d74
010224a
6ae09c5
670a9c2
240c72d
565dfe2
3384ab0
4e38057
8c97549
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| const util = require('util'); | ||
| const internalUtil = require('internal/util'); | ||
| const promisify = require('internal/promisify'); | ||
| const debug = util.debuglog('child_process'); | ||
| const constants = require('constants'); | ||
|
|
||
|
|
@@ -102,6 +103,9 @@ exports.exec = function(command /*, options, callback*/) { | |
| }; | ||
|
|
||
|
|
||
| exports.execAsync = promisify(exports.exec); | ||
|
|
||
|
|
||
| exports.execFile = function(file /*, args, options, callback*/) { | ||
| var args = [], callback; | ||
| var options = { | ||
|
|
@@ -288,6 +292,10 @@ exports.execFile = function(file /*, args, options, callback*/) { | |
| return child; | ||
| }; | ||
|
|
||
|
|
||
| exports.execFileAsync = promisify(exports.execFile); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @chrisdickinson something like that came to my mind: exports.execFileAsync = exports.execFile;
process.promisify === true ? exports.execFileAsync = promisify(exports.execFile) : 0;There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @eljefedelrodeodeljefe Third party libraries wont be able to use this then as
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. Chris just mentioned a possible opt-out via flag. I'll see where this goes. |
||
|
|
||
|
|
||
| var _deprecatedCustomFds = internalUtil.deprecate(function(options) { | ||
| options.stdio = options.customFds.map(function(fd) { | ||
| return fd === -1 ? 'pipe' : fd; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very uncomfortable with this kind of returns something or Promise kind of pattern. I would rather have a
sendAsynckind of variant that always returns a Promise and keepsendas it is. Overloading return values can get become problematic for developers who aren't careful.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to clarify, one example of how this could become tricky is that the return value on
child.send()will be false if thewhen the backlog of unsent messages exceeds a threshold that makes it unwise to send more, which means a developer can currently depend on the return value being falsy to help with throttling or to provide backpressure. If code is sending a bunch of messages and doesn't care about the callback, then a falsy check would fail...The fact that
callbackis already optional onsendjust makes this unpredictable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A+, will change. This will likely influence how we approach this with streams as well, since the child process message functionality technically should be a stream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it common to node APIs or
process.send()is an outlier? I don't remember ever using that return-and-callback-too pattern.Let me explain my concerns: "return a promise if no callback was provided" seems to be the least annoying way to support async/await. The other option is having a parallel API. Is
process.send()the only thing that holds it back?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gritzko The
crypto.randomBytesfunction is already dual-mode - it will act synchronously without a callback, and asynchronously with a callback. While a different situation fromsend, I'd imagine it would interfere in a similar way.