Aurvion / llama.cpp /tools /ui /src /lib /utils /debounce.ts
OmnipotentFool's picture
Add files using upload-large-folder tool
6b9d0d8 verified
Raw History Blame Contribute Delete
534 Bytes
/**
* @param fn - The function to debounce
* @param delay - The delay in milliseconds
* @returns A debounced version of the function
*/
export function debounce<T extends (...args: Parameters<T>) => void>(
fn: T,
delay: number
): (...args: Parameters<T>) => void {
let timeoutId: ReturnType<typeof setTimeout> | null = null;
return (...args: Parameters<T>) => {
if (timeoutId) {
clearTimeout(timeoutId);
}
timeoutId = setTimeout(() => {
fn(...args);
timeoutId = null;
}, delay);
};
}