revenge-bundle-next/lib/utils/src/callback.ts

16 lines
388 B
TypeScript
Raw Normal View History

2025-06-03 16:24:58 +07:00
export function debounce<F extends (...args: any[]) => any>(
func: F,
timeout: number,
) {
2025-04-15 14:22:41 +07:00
let timer: Parameters<typeof clearTimeout>[0]
return (...args: Parameters<F>) =>
new Promise(rs => {
clearTimeout(timer)
timer = setTimeout(() => {
rs(func(...args))
}, timeout)
2025-04-15 14:22:41 +07:00
})
}
2025-06-14 17:54:04 +07:00
export const noop = () => {}