Skip to content

Commit b98cc51

Browse files
Trottdanielleadams
authored andcommitted
child_process: reduce abort handler code duplication
Move duplicate abort handler logic into a separate function. PR-URL: #36644 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Daijiro Wachi <[email protected]>
1 parent 78d4d91 commit b98cc51

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

lib/child_process.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,12 @@ function execFile(file /* , args, options, callback */) {
368368
}
369369
}
370370

371+
function abortHandler() {
372+
if (!ex)
373+
ex = new AbortError();
374+
process.nextTick(() => kill());
375+
}
376+
371377
if (options.timeout > 0) {
372378
timeoutId = setTimeout(function delayedKill() {
373379
kill();
@@ -376,16 +382,11 @@ function execFile(file /* , args, options, callback */) {
376382
}
377383
if (options.signal) {
378384
if (options.signal.aborted) {
379-
if (!ex)
380-
ex = new AbortError();
381-
process.nextTick(() => kill());
385+
process.nextTick(abortHandler);
382386
} else {
383387
const childController = new AbortController();
384-
options.signal.addEventListener('abort', () => {
385-
if (!ex)
386-
ex = new AbortError();
387-
kill();
388-
}, { signal: childController.signal });
388+
options.signal.addEventListener('abort', abortHandler,
389+
{ signal: childController.signal });
389390
child.once('close', () => childController.abort());
390391
}
391392
}

0 commit comments

Comments
 (0)