Files
yaak-mountain-loop/packages/common-lib/debounce.ts
2025-11-23 08:38:13 -08:00

14 lines
414 B
TypeScript

// biome-ignore lint/suspicious/noExplicitAny: none
export function debounce(fn: (...args: any[]) => void, delay = 500) {
let timer: ReturnType<typeof setTimeout>;
// biome-ignore lint/suspicious/noExplicitAny: none
const result = (...args: any[]) => {
clearTimeout(timer);
timer = setTimeout(() => fn(...args), delay);
};
result.cancel = () => {
clearTimeout(timer);
};
return result;
}