mirror of
https://github.com/toss/es-toolkit.git
synced 2024-11-24 11:45:26 +03:00
79046ea5c1
* feat: add support for variable arguments in debounce.ts * feat: add support for variable arguments in throttle.ts * Update src/function/debounce.ts * Apply suggestions from code review * Update src/function/debounce.ts * Update src/function/throttle.ts * docs: update related docs --------- Co-authored-by: Sojin Park <raon0211@gmail.com> Co-authored-by: Sojin Park <raon0211@toss.im>
929 B
929 B
throttle
Creates a throttled function that only invokes the provided function at most once
per every throttleMs
milliseconds. Subsequent calls to the throttled function
within the wait time will not trigger the execution of the original function.
Signature
function throttle<F extends (...args: any[]) => void>(func: F, throttleMs: number): F;
Parameters
func
(F
): The function to throttle.throttleMs
(number
): The number of milliseconds to throttle executions to.
Returns
(F
): A new throttled function.
Examples
const throttledFunction = throttle(() => {
console.log('Function executed');
}, 1000);
// Will log 'Function executed' immediately
throttledFunction();
// Will not log anything as it is within the throttle time
throttledFunction();
// After 1 second
setTimeout(() => {
throttledFunction(); // Will log 'Function executed'
}, 1000);