Skip to content

Commit

Permalink
child_process: reduce abort handler code duplication
Browse files Browse the repository at this point in the history
Move duplicate abort handler logic into a separate function.

PR-URL: #36644
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Daijiro Wachi <[email protected]>
  • Loading branch information
Trott authored and targos committed May 25, 2021
1 parent ecc600b commit ee7bc76
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,12 @@ function execFile(file /* , args, options, callback */) {
}
}

function abortHandler() {
if (!ex)
ex = new AbortError();
process.nextTick(() => kill());
}

if (options.timeout > 0) {
timeoutId = setTimeout(function delayedKill() {
kill();
Expand All @@ -362,16 +368,11 @@ function execFile(file /* , args, options, callback */) {
}
if (options.signal) {
if (options.signal.aborted) {
if (!ex)
ex = new AbortError();
process.nextTick(() => kill());
process.nextTick(abortHandler);
} else {
const childController = new AbortController();
options.signal.addEventListener('abort', () => {
if (!ex)
ex = new AbortError();
kill();
}, { signal: childController.signal });
options.signal.addEventListener('abort', abortHandler,
{ signal: childController.signal });
child.once('close', () => childController.abort());
}
}
Expand Down

0 comments on commit ee7bc76

Please sign in to comment.