mirror of
https://github.com/nodejs/node.git
synced 2026-11-30 11:55:44 -05:00
net: 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
002ce31cca
commit
ac11264cc5
1 file changed
+6
-4
+6
-4
@@ -35,6 +35,7 @@ const {
|
||||
ObjectDefineProperty,
|
||||
ObjectSetPrototypeOf,
|
||||
Symbol,
|
||||
SymbolDispose,
|
||||
} = primordials;
|
||||
|
||||
const EventEmitter = require('events');
|
||||
@@ -1605,9 +1606,10 @@ function afterConnect(status, handle, req, readable, writable) {
|
||||
function addClientAbortSignalOption(self, options) {
|
||||
validateAbortSignal(options.signal, 'options.signal');
|
||||
const { signal } = options;
|
||||
let disposable;
|
||||
|
||||
function onAbort() {
|
||||
signal.removeEventListener('abort', onAbort);
|
||||
disposable?.[SymbolDispose]();
|
||||
self._aborted = true;
|
||||
}
|
||||
|
||||
@@ -1615,7 +1617,7 @@ function addClientAbortSignalOption(self, options) {
|
||||
process.nextTick(onAbort);
|
||||
} else {
|
||||
process.nextTick(() => {
|
||||
signal.addEventListener('abort', onAbort);
|
||||
disposable = EventEmitter.addAbortListener(signal, onAbort);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1695,8 +1697,8 @@ function addServerAbortSignalOption(self, options) {
|
||||
if (signal.aborted) {
|
||||
process.nextTick(onAborted);
|
||||
} else {
|
||||
signal.addEventListener('abort', onAborted);
|
||||
self.once('close', () => signal.removeEventListener('abort', onAborted));
|
||||
const disposable = EventEmitter.addAbortListener(signal, onAborted);
|
||||
self.once('close', disposable[SymbolDispose]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user