MCPcopy Create free account
hub / github.com/TanStack/cli / DebounceQueue

Class DebounceQueue

packages/cli/src/dev-watch.ts:44–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42}
43
44class 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
83export class DevWatchManager {
84 private watcher: FSWatcher | null = null

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected