bolt.diy/app/utils/debounce.ts

14 lines
369 B
TypeScript
Raw Normal View History

2025-02-18 13:13:13 +00:00
export function debounce<T extends (...args: any[]) => any>(func: T, wait: number): (...args: Parameters<T>) => void {
let timeout: NodeJS.Timeout;
2025-02-18 13:13:13 +00:00
return function executedFunction(...args: Parameters<T>) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
2025-02-18 13:13:13 +00:00
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
}