mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
child_process: use addAbortListener
PR-URL: https://github.com/nodejs/node/pull/48550 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
1 parent
f3c4300e00
commit
b5df084e1e
1 file changed
+5
-3
@@ -42,6 +42,7 @@ const {
|
||||
StringPrototypeIncludes,
|
||||
StringPrototypeSlice,
|
||||
StringPrototypeToUpperCase,
|
||||
SymbolDispose,
|
||||
} = primordials;
|
||||
|
||||
const {
|
||||
@@ -95,6 +96,7 @@ const {
|
||||
const MAX_BUFFER = 1024 * 1024;
|
||||
|
||||
const isZOS = process.platform === 'os390';
|
||||
let addAbortListener;
|
||||
|
||||
/**
|
||||
* Spawns a new Node.js process + fork.
|
||||
@@ -781,9 +783,9 @@ function spawn(file, args, options) {
|
||||
if (signal.aborted) {
|
||||
process.nextTick(onAbortListener);
|
||||
} else {
|
||||
signal.addEventListener('abort', onAbortListener, { once: true });
|
||||
child.once('exit',
|
||||
() => signal.removeEventListener('abort', onAbortListener));
|
||||
addAbortListener ??= require('events').addAbortListener;
|
||||
const disposable = addAbortListener(signal, onAbortListener);
|
||||
child.once('exit', disposable[SymbolDispose]);
|
||||
}
|
||||
|
||||
function onAbortListener() {
|
||||
|
||||
Reference in new issue
Block a user