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 <benjamingr@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
  • Loading branch information
Trott authored and danielleadams committed Jan 12, 2021
1 parent 78d4d91 commit b98cc51
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 @@ -368,6 +368,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 @@ -376,16 +382,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 b98cc51

Please sign in to comment.