throttle
throttle<
T>(params):Throttled<T>
Defined in: async/throttle/index.ts:24
Creates a throttled version of a function that executes at most once
every ms milliseconds.
Type Parameters
Section titled “Type Parameters”T extends (…args) => unknown
Parameters
Section titled “Parameters”params
Section titled “params”ThrottleParams<T>
The parameters object
Returns
Section titled “Returns”Throttled<T>
The throttled function with a .cancel() method
Example
Section titled “Example”const throttledFn = throttle({ fn: onScroll, ms: 100 });window.addEventListener("scroll", throttledFn);throttledFn.cancel(); // cancel pending trailing callKeywords
Section titled “Keywords”rate limit, limit calls, scroll handler, resize handler
Throws
Section titled “Throws”Error if fn is not a function
Throws
Section titled “Throws”Error if ms is not a number or is negative