summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2019-06-20 12:10:06 -0400
committerMichaƫl Zasso <targos@protonmail.com>2019-07-02 09:07:46 +0200
commitdd5e07f9b4447f21919aea4688df757225935a21 (patch)
tree505d395ddb2e6cdce50f398d4f741f52f8c86b4c /lib
parent632fc1faf5aecdf9a2966c4e92e598c613d56a7d (diff)
downloadandroid-node-v8-dd5e07f9b4447f21919aea4688df757225935a21.tar.gz
android-node-v8-dd5e07f9b4447f21919aea4688df757225935a21.tar.bz2
android-node-v8-dd5e07f9b4447f21919aea4688df757225935a21.zip
child_process: attach child in promisification
This commit updates the custom exec() and execFile() promisification to attach the ChildProcess instance to the returned Promise. PR-URL: https://github.com/nodejs/node/pull/28325 Fixes: https://github.com/nodejs/node/issues/28244 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Wyatt Preul <wpreul@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/child_process.js27
1 files changed, 17 insertions, 10 deletions
diff --git a/lib/child_process.js b/lib/child_process.js
index 66be7611dc..0d3785f0d5 100644
--- a/lib/child_process.js
+++ b/lib/child_process.js
@@ -149,17 +149,24 @@ function exec(command, options, callback) {
const customPromiseExecFunction = (orig) => {
return (...args) => {
- return new Promise((resolve, reject) => {
- orig(...args, (err, stdout, stderr) => {
- if (err !== null) {
- err.stdout = stdout;
- err.stderr = stderr;
- reject(err);
- } else {
- resolve({ stdout, stderr });
- }
- });
+ let resolve;
+ let reject;
+ const promise = new Promise((res, rej) => {
+ resolve = res;
+ reject = rej;
});
+
+ promise.child = orig(...args, (err, stdout, stderr) => {
+ if (err !== null) {
+ err.stdout = stdout;
+ err.stderr = stderr;
+ reject(err);
+ } else {
+ resolve({ stdout, stderr });
+ }
+ });
+
+ return promise;
};
};