throttle 'tilts' from the server
This commit is contained in:
12
tools/throttle.ts
Normal file
12
tools/throttle.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export default function throttle(func: Function, threshold: number) {
|
||||
let lastCall = 0;
|
||||
|
||||
return (...args: any[]) => {
|
||||
const now = Date.now();
|
||||
|
||||
if (now - lastCall >= threshold) {
|
||||
lastCall = now;
|
||||
func(...args);
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user