-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
watch: Debounce all files updates into a single event. #51988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
768da12
906f7c8
e2ce54a
ada7280
f2e2232
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -24,9 +24,10 @@ const supportsRecursiveWatching = process.platform === 'win32' || | |||||
| class FilesWatcher extends EventEmitter { | ||||||
| #watchers = new SafeMap(); | ||||||
| #filteredFiles = new SafeSet(); | ||||||
| #debouncing = new SafeSet(); | ||||||
| #depencencyOwners = new SafeMap(); | ||||||
| #ownerDependencies = new SafeMap(); | ||||||
| #debounceOwners = new SafeSet(); | ||||||
| #debounceTimer; | ||||||
| #debounce; | ||||||
| #mode; | ||||||
| #signal; | ||||||
|
|
@@ -74,17 +75,19 @@ class FilesWatcher extends EventEmitter { | |||||
| } | ||||||
|
|
||||||
| #onChange(trigger) { | ||||||
| if (this.#debouncing.has(trigger)) { | ||||||
| return; | ||||||
| } | ||||||
| if (this.#mode === 'filter' && !this.#filteredFiles.has(trigger)) { | ||||||
| return; | ||||||
| } | ||||||
| this.#debouncing.add(trigger); | ||||||
|
|
||||||
| const owners = this.#depencencyOwners.get(trigger); | ||||||
| setTimeout(() => { | ||||||
| this.#debouncing.delete(trigger); | ||||||
| if (owners) for (const o of owners) this.#debounceOwners.add(o); | ||||||
|
|
||||||
| clearTimeout(this.#debounceTimer); | ||||||
| this.#debounceTimer = setTimeout(() => { | ||||||
| this.#debounceTimer = null; | ||||||
| const owners = this.#debounceOwners; | ||||||
| this.emit('changed', { owners }); | ||||||
| this.#debounceOwners = new SafeSet(); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason I did that is to allow async processing of the const owners = new Set(this.#debounceOwners);
this.emit('changed', { owners });
this.#debounceOwners.clear();What do you think ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you think that async processing of the event is not something we should care about here, then I can just implement your change. |
||||||
| }, this.#debounce).unref(); | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.