Skip to content

Commit 57ac709

Browse files
MoLowmatthieusieben
andcommitted
watch: add global debounce
Co-authored-by: Matthieu <matthieusieben@users.noreply.github.com>
1 parent 384fd17 commit 57ac709

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/internal/watch_mode/files_watcher.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const {
66
SafeMap,
77
SafeSet,
88
StringPrototypeStartsWith,
9+
Symbol,
910
} = primordials;
1011

1112
const { validateNumber, validateOneOf } = require('internal/validators');
@@ -21,6 +22,7 @@ const { setTimeout } = require('timers');
2122
const supportsRecursiveWatching = process.platform === 'win32' ||
2223
process.platform === 'darwin';
2324

25+
const kGlobalDebounce = Symbol('kGlobalDebounce');
2426
class FilesWatcher extends EventEmitter {
2527
#watchers = new SafeMap();
2628
#filteredFiles = new SafeSet();
@@ -74,16 +76,17 @@ class FilesWatcher extends EventEmitter {
7476
}
7577

7678
#onChange(trigger) {
77-
if (this.#debouncing.has(trigger)) {
79+
if (this.#debouncing.has(trigger) || this.#debouncing.has(kGlobalDebounce)) {
7880
return;
7981
}
8082
if (this.#mode === 'filter' && !this.#filteredFiles.has(trigger)) {
8183
return;
8284
}
83-
this.#debouncing.add(trigger);
85+
this.#debouncing.add(trigger).add(kGlobalDebounce);
8486
const owners = this.#depencencyOwners.get(trigger);
8587
setTimeout(() => {
8688
this.#debouncing.delete(trigger);
89+
this.#debouncing.delete(kGlobalDebounce);
8790
this.emit('changed', { owners });
8891
}, this.#debounce).unref();
8992
}

0 commit comments

Comments
 (0)