jcloud/dashboard/src2/utils/throttle.ts
2025-04-12 17:39:38 +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);
};
}