mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-17 17:32:15 +08:00
13 lines
353 B
TypeScript
13 lines
353 B
TypeScript
export default function debounce<T extends (...args: any[]) => void>(
|
|
func: T,
|
|
wait: number,
|
|
): T {
|
|
let timeout: ReturnType<typeof setTimeout> | null = null
|
|
return function (this: any, ...args: Parameters<T>) {
|
|
if (timeout !== null) {
|
|
clearTimeout(timeout)
|
|
}
|
|
timeout = setTimeout(() => func.apply(this, args), wait)
|
|
} as T
|
|
}
|