Skip to content

Commit e5fae63

Browse files
Trotttargos
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 <benjamingr@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
1 parent 598d2bd commit e5fae63

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
@@ -354,6 +354,12 @@ function execFile(file /* , args, options, callback */) {
354354
}
355355
}
356356

357+
function abortHandler() {
358+
if (!ex)
359+
ex = new AbortError();
360+
process.nextTick(() => kill());
361+
}
362+
357363
if (options.timeout > 0) {
358364
timeoutId = setTimeout(function delayedKill() {
359365
kill();
@@ -362,16 +368,11 @@ function execFile(file /* , args, options, callback */) {
362368
}
363369
if (options.signal) {
364370
if (options.signal.aborted) {
365-
if (!ex)
366-
ex = new AbortError();
367-
process.nextTick(() => kill());
371+
process.nextTick(abortHandler);
368372
} else {
369373
const childController = new AbortController();
370-
options.signal.addEventListener('abort', () => {
371-
if (!ex)
372-
ex = new AbortError();
373-
kill();
374-
}, { signal: childController.signal });
374+
options.signal.addEventListener('abort', abortHandler,
375+
{ signal: childController.signal });
375376
child.once('close', () => childController.abort());
376377
}
377378
}

0 commit comments

Comments
 (0)