mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
child_process: reduce abort handler code duplication
Move duplicate abort handler logic into a separate function. PR-URL: https://github.com/nodejs/node/pull/36644 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
This commit is contained in:
1 parent
598d2bdf09
commit
e5fae63108
1 file changed
+9
-8
@@ -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();
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user