MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / makeDebouncer

Function makeDebouncer

src/artifacts/live-server.ts:79–87  ·  view source on GitHub ↗
(fn: () => void, ms: number)

Source from the content-addressed store, hash-verified

77/** A trailing debouncer: N rapid calls collapse into one invocation after `ms` of quiet.
78 * Returned function exposes `.cancel()` to clear a pending call (used on close). */
79export function makeDebouncer(fn: () => void, ms: number): (() => void) & { cancel: () => void } {
80 let timer: ReturnType<typeof setTimeout> | null = null;
81 const debounced = () => {
82 if (timer) clearTimeout(timer);
83 timer = setTimeout(() => { timer = null; fn(); }, ms);
84 };
85 debounced.cancel = () => { if (timer) { clearTimeout(timer); timer = null; } };
86 return debounced;
87}
88
89/** Build the page served for GET / : current version → preview HTML → live-reload injected.
90 * Any failure becomes a valid error-overlay page (still hashable, still self-recovering). */

Callers 2

createLiveServerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected