Skip to content

Commit

Permalink
lib: use addAbortListener
Browse files Browse the repository at this point in the history
PR-URL: #48550
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
atlowChemi authored and ruyadorno committed Sep 12, 2023
1 parent 24eeae3 commit 33c9cea
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 @@ -447,7 +448,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 33c9cea

Please sign in to comment.