throttle es-toolkit
Limits a function to be executed at most once per specified time interval.
Usage
throttle(func, throttleMs, options?)
Use throttle when you want to limit function calls to a specific time interval. This is useful for optimizing performance when handling frequently occurring events like scrolling, resizing, or mouse movement.
Unlike debounce, throttle ensures the function is executed at least once during the specified time period.
You can adjust the leading and trailing options.
You can also control it manually.
Parameters
The function to throttle.
The time interval (in milliseconds) to throttle execution.
Additional options.
signal(AbortSignal, optional): A signal that can cancel function execution.edges(Array<'leading' | 'trailing'>, optional): Determines when to execute the function. Defaults to['leading', 'trailing'].
Returns
Returns a new throttled function with cancel and flush methods.
Source: es-toolkit
Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.