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)
|
2025-06-14 17:53:28 +07:00
|
|
|
timer = setTimeout(() => rs(func(...args)), timeout)
|
2025-04-15 14:22:41 +07:00
|
|
|
})
|
|
|
|
|
}
|
2025-05-18 22:24:48 +07:00
|
|
|
|
|
|
|
|
export const noopFalse = () => false
|
2025-06-14 17:54:04 +07:00
|
|
|
export const noop = () => {}
|