Skip to content

Commit

Permalink
remove exit handler on exit
Browse files Browse the repository at this point in the history
  • Loading branch information
also committed Feb 11, 2018
1 parent fcb4f6a commit 5d7f355
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,15 @@ module.exports = (cmd, args, opts) => {
let timeoutId = null;
let timedOut = false;

const cleanupTimeout = () => {
const cleanup = () => {
if (timeoutId) {
clearTimeout(timeoutId);
timeoutId = null;
}

if (removeExitHandler) {
removeExitHandler();
}
};

if (parsed.opts.timeout > 0) {
Expand All @@ -233,18 +237,18 @@ module.exports = (cmd, args, opts) => {

const processDone = new Promise(resolve => {
spawned.on('exit', (code, signal) => {
cleanupTimeout();
cleanup();
resolve({code, signal});
});

spawned.on('error', err => {
cleanupTimeout();
cleanup();
resolve({error: err});
});

if (spawned.stdin) {
spawned.stdin.on('error', err => {
cleanupTimeout();
cleanup();
resolve({error: err});
});
}
Expand All @@ -269,10 +273,6 @@ module.exports = (cmd, args, opts) => {
result.stdout = arr[1];
result.stderr = arr[2];

if (removeExitHandler) {
removeExitHandler();
}

if (result.error || result.code !== 0 || result.signal !== null) {
const err = makeError(result, {
joinedCmd,
Expand Down

0 comments on commit 5d7f355

Please sign in to comment.