throttleit
Throttle a function to limit its execution rate
Install
npm install throttleit
Usage
import throttle from 'throttleit';
function processData(data) {
console.log('Processing:', data);
}
const throttledProcessData = throttle(processData, 3000);
throttledProcessData('Data 1');
throttledProcessData('Data 2');
throttledProcessData('Data 3');
API
throttle(function, wait)
Creates a throttled function that limits calls to the original function to at most once every wait
milliseconds. It guarantees execution after the final invocation and maintains the last context (this
) and arguments.
function
Type: function
The function to be throttled.
wait
Type: number
The number of milliseconds to throttle invocations to.
Related
- p-throttle - Throttle async functions
- debounce - Delay function calls until a set time elapses after the last invocation