The return type of the function.
The async function to throttle.
Minimum milliseconds between executions.
Optionaloptions: ThrottleOptionsThrottle configuration options.
A throttled function with cancel, flush, and pending methods.
const saveData = throttle(
async (data: string) => {
return await api.save(data);
},
1000,
);
saveData("a"); // Executes immediately
saveData("b"); // Queued, executes after 1000ms
saveData("c"); // Replaces "b", executes after 1000ms
// Cancel pending execution
saveData.cancel();
// Execute immediately
saveData.flush();
Creates a throttled version of an async function. The function will execute at most once per wait period, regardless of how many times it's called.