2025-12-28 00:20:10 +08:00

21 lines
343 B
TypeScript

export function throttle(func: Function, wait: number) {
let timeout = 0;
let pending = false;
return (...args: any) => {
if (timeout) {
pending = true;
return;
}
func(...args);
timeout = setTimeout(() => {
timeout = 0;
if (pending) {
func(...args);
pending = false;
}
}, wait);
};
}