Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
promisified exec and execFile should return a promise with ChildProce…
Browse files Browse the repository at this point in the history
…ss instance attached (#880)
  • Loading branch information
onip authored Mar 26, 2021
1 parent e463acc commit 9bb4f70
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions prelude/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -1660,22 +1660,30 @@ function payloadFileSync(pointer) {
// CHILD_PROCESS ///////////////////////////////////////////////
// /////////////////////////////////////////////////////////////

var customPromiseExecFunction = (o) => (...args) =>
new Promise((resolve, reject) => {
o.apply(
undefined,
args.concat((error, stdout, stderr) => {
if (error !== null) {
error.stdout = stdout;
error.stderr = stderr;
reject(error);
} else {
resolve({ stdout, stderr });
}
})
);
var customPromiseExecFunction = (o) => (...args) => {
let resolve;
let reject;
const p = new Promise((res, rej) => {
resolve = res;
reject = rej;
});

p.child = o.apply(
undefined,
args.concat((error, stdout, stderr) => {
if (error !== null) {
error.stdout = stdout;
error.stderr = stderr;
reject(error);
} else {
resolve({ stdout, stderr });
}
})
);

return p;
};

Object.defineProperty(require('child_process').exec, custom, {
value: customPromiseExecFunction(require('child_process').exec),
});
Expand Down

0 comments on commit 9bb4f70

Please sign in to comment.