Wraps an async function to enforce a minimum delay between consecutive executions.
Additional calls are queued and processed in FIFO order. Useful for throttling API calls.
Tuple of the function's parameter types.
The resolved return type.
The async function to rate-limit.
Minimum delay (ms), or a function returning the delay dynamically.
A RateLimitedFunction.
const limitedFetch = rateLimited(fetchJson, 500);await limitedFetch("/endpoint"); // executes immediatelyawait limitedFetch("/endpoint"); // queued, executes ≥500ms later Copy
const limitedFetch = rateLimited(fetchJson, 500);await limitedFetch("/endpoint"); // executes immediatelyawait limitedFetch("/endpoint"); // queued, executes ≥500ms later
Wraps an async function to enforce a minimum delay between consecutive executions.
Additional calls are queued and processed in FIFO order. Useful for throttling API calls.