| 1 |
export type MessageToWorker = |
| 2 |
| { kind: 'parse'; source: string } |
| 3 |
| { kind: 'print'; messageId: number; bytes: Uint8Array, skeleton: boolean }; |
| 4 |
|
| 5 |
export function debounce(f: (...args: unknown[]) => void, ms: number) { |
| 6 |
let timeout: number | null; |
| 7 |
return function (this: unknown, ...args: unknown[]) { |
| 8 |
let fresh = timeout == null; |
| 9 |
if (!fresh) clearTimeout(timeout!); |
| 10 |
timeout = setTimeout(() => { |
| 11 |
timeout = null; |
| 12 |
if (!fresh) f.apply(this, args); |
| 13 |
}, ms); |
| 14 |
if (fresh) f.apply(this, args); |
| 15 |
}; |
| 16 |
} |