| 42 | } |
| 43 | |
| 44 | class DebounceQueue { |
| 45 | private timer: NodeJS.Timeout | null = null |
| 46 | private changes: Set<string> = new Set() |
| 47 | private callback: (changes: Set<string>) => void |
| 48 | |
| 49 | constructor( |
| 50 | callback: (changes: Set<string>) => void, |
| 51 | private delay: number = 1000, |
| 52 | ) { |
| 53 | this.callback = callback |
| 54 | } |
| 55 | |
| 56 | add(path: string): void { |
| 57 | this.changes.add(path) |
| 58 | |
| 59 | if (this.timer) { |
| 60 | clearTimeout(this.timer) |
| 61 | } |
| 62 | |
| 63 | this.timer = setTimeout(() => { |
| 64 | const currentChanges = new Set(this.changes) |
| 65 | this.callback(currentChanges) |
| 66 | this.changes.clear() |
| 67 | }, this.delay) |
| 68 | } |
| 69 | |
| 70 | size(): number { |
| 71 | return this.changes.size |
| 72 | } |
| 73 | |
| 74 | clear(): void { |
| 75 | if (this.timer) { |
| 76 | clearTimeout(this.timer) |
| 77 | this.timer = null |
| 78 | } |
| 79 | this.changes.clear() |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | export class DevWatchManager { |
| 84 | private watcher: FSWatcher | null = null |
nothing calls this directly
no outgoing calls
no test coverage detected