1
0
Fork 0
mirror of https://github.com/kou029w/quot.git synced 2025-01-19 00:18:09 +00:00
quot/app/src/helpers/throttle.ts

22 lines
437 B
TypeScript
Raw Normal View History

2022-08-24 09:50:35 +09:00
function throttle<Fn extends (...args: any[]) => any>(
fn: Fn,
ms: number
): (...args: Parameters<Fn>) => void {
let throttledFn = () => undefined;
let throttled: boolean = false;
return (...args: Parameters<Fn>): void => {
throttledFn = () => fn(...args);
if (throttled) return;
setTimeout(() => {
throttledFn();
throttled = false;
}, ms);
throttled = true;
};
}
export default throttle;