-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
Get the child from promisified childProcess.execFile
#28244
Comments
Sounds like a reasonable use case to me. Adding a new symbol to promises returned from const kResult = Symbol('kResult');
const promisify = func => (...args) => {
let resolve, reject;
return Object.assign(new Promise((res, rej) => {
resolve = res;
reject = rej;
}), {
[kResult]: func(...args, (err, result) => {
const f = () => {
if(!resolve) return setTimeout(f);
if(err) reject(err);
else resolve(result);
}
f();
}),
});
};
const promise = promisify(cp.exec)('node -v');
console.log(promise[kResult].pid);
promise.then(a => console.log(String(a))); |
4 tasks
cjihrig
added a commit
to cjihrig/node
that referenced
this issue
Jun 22, 2019
This commit updates the custom exec() and execFile() promisification to attach the ChildProcess instance to the returned Promise. PR-URL: nodejs#28325 Fixes: nodejs#28244 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Wyatt Preul <wpreul@gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
When using
childProcess.execFile()
, it returns the child, but there's no way to access the child when usingpromisify(childProcess.execFile)()
. I want to use the promise version for async/await, but I also need to access the child, specifically the.pid
.Describe the solution you'd like
It would be useful if the
child
could be attached to the promise as a property:Describe alternatives you've considered
The child could also be returned in the promise result along with
stdout
andstderr
, but there are cases where it would be useful to access the child synchronously.I could keep using the callback-version, but I don't think that's a good solution. Async/await is the future. The promise version should at least be as powerful as the callback version.
This applies to
childProcess.exec
too.The text was updated successfully, but these errors were encountered: