Creates a throttled version of an asynchronous function.
Ensures that the function is invoked at most once per specified interval. Subsequent calls within the interval return the pending promise from the previous call.
The async function type.
The asynchronous function to throttle.
Minimum time in milliseconds between function invocations.
A throttled async function with the same signature as fn.
fn
const fetchData = async (id: number) => { console.log("Fetching", id); return id;};const throttled = throttleAsync(fetchData, 1000);await throttled(1); // Executesawait throttled(2); // Returns previous pending promise Copy
const fetchData = async (id: number) => { console.log("Fetching", id); return id;};const throttled = throttleAsync(fetchData, 1000);await throttled(1); // Executesawait throttled(2); // Returns previous pending promise
1.1.0
Creates a throttled version of an asynchronous function.
Ensures that the function is invoked at most once per specified interval. Subsequent calls within the interval return the pending promise from the previous call.