Skip to content

Commit

Permalink
Small refactoring on cleanup option (#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky authored and sindresorhus committed May 30, 2019
1 parent e5ed8de commit 3b103f8
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,9 @@ const execa = (file, args, options) => {
return promise;
})();

const processDone = new Promise(resolve => {
// TODO: Use native "finally" syntax when targeting Node.js 10
const processDone = pFinally(new Promise(resolve => {
spawned.on('exit', (code, signal) => {
cleanup();

if (timedOut) {
resolvable.resolve([
{code, signal}, '', '', ''
Expand All @@ -281,17 +280,15 @@ const execa = (file, args, options) => {
});

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

if (spawned.stdin) {
spawned.stdin.on('error', error => {
cleanup();
resolve({error});
});
}
});
}), cleanup);

function destroy() {
if (spawned.stdout) {
Expand Down

0 comments on commit 3b103f8

Please sign in to comment.