Skip to content

Commit

Permalink
lib: use addAbortListener
Browse files Browse the repository at this point in the history
PR-URL: nodejs#48550
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
  • Loading branch information
atlowChemi authored and Ceres6 committed Aug 14, 2023
1 parent d73d83c commit 8a02767
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/internal/abort_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const {
kTrustEvent,
kNewListener,
kRemoveListener,
kResistStopPropagation,
kWeakHandler,
} = require('internal/event_target');
const {
Expand Down Expand Up @@ -439,7 +440,8 @@ async function aborted(signal, resource) {
if (signal.aborted)
return PromiseResolve();
const abortPromise = createDeferredPromise();
signal.addEventListener('abort', abortPromise.resolve, { [kWeakHandler]: resource, once: true });
const opts = { __proto__: null, [kWeakHandler]: resource, once: true, [kResistStopPropagation]: true };
signal.addEventListener('abort', abortPromise.resolve, opts);
return abortPromise.promise;
}

Expand Down
5 changes: 3 additions & 2 deletions lib/internal/watch_mode/files_watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const { fileURLToPath } = require('url');
const { resolve, dirname } = require('path');
const { setTimeout } = require('timers');


const supportsRecursiveWatching = process.platform === 'win32' ||
process.platform === 'darwin';

Expand All @@ -41,7 +40,9 @@ class FilesWatcher extends EventEmitter {
this.#mode = mode;
this.#signal = signal;

signal?.addEventListener('abort', () => this.clear(), { __proto__: null, once: true });
if (signal) {
EventEmitter.addAbortListener(signal, () => this.clear());
}
}

#isPathWatched(path) {
Expand Down

0 comments on commit 8a02767

Please sign in to comment.