Download mobile/modules/engine/src/utils/debouncedPatch.ts from Anirudh1950/MentraOS: direct link, hf CLI and curl.
- Browser
- Download file 811 Bytes
-
https://huggingface.co/Anirudh1950/MentraOS/resolve/main/mobile/modules/engine/src/utils/debouncedPatch.ts
- Command line
-
hf download hf://Anirudh1950/MentraOS/mobile/modules/engine/src/utils/debouncedPatch.ts
-
curl -L -o debouncedPatch.ts https://huggingface.co/Anirudh1950/MentraOS/resolve/main/mobile/modules/engine/src/utils/debouncedPatch.ts
811 Bytes
| /** | |
| * Merge partial patches and flush once after `delayMs` of quiet time. | |
| * Uses global setTimeout so Jest fake timers can advance debounced writes. | |
| */ | |
| export function createDebouncedPatchFlusher<T extends Record<string, unknown>>( | |
| flush: (patch: T) => void, | |
| delayMs: number, | |
| ) { | |
| let pending = {} as T | |
| let timer: ReturnType<typeof setTimeout> | null = null | |
| const schedule = (callback: () => void) => { | |
| timer = setTimeout(callback, delayMs) as ReturnType<typeof setTimeout> | |
| } | |
| return (patch: Partial<T>) => { | |
| pending = {...pending, ...patch} | |
| if (timer != null) { | |
| clearTimeout(timer) | |
| } | |
| schedule(() => { | |
| timer = null | |
| const batch = pending | |
| pending = {} as T | |
| if (Object.keys(batch).length > 0) flush(batch) | |
| }) | |
| } | |
| } | |