Defined in: async-rate-limiter.ts:7
Options for configuring an async rate-limited function
• TFn extends AnyAsyncFunction
optional enabled: boolean | (rateLimiter) => boolean;
optional enabled: boolean | (rateLimiter) => boolean;
Defined in: async-rate-limiter.ts:13
Whether the rate limiter is enabled. When disabled, maybeExecute will not trigger any executions. Can be a boolean or a function that returns a boolean. Defaults to true.
limit: number | (rateLimiter) => number;
limit: number | (rateLimiter) => number;
Defined in: async-rate-limiter.ts:18
Maximum number of executions allowed within the time window. Can be a number or a function that returns a number.
optional onError: (error, rateLimiter) => void;
optional onError: (error, rateLimiter) => void;
Defined in: async-rate-limiter.ts:24
Optional error handler for when the rate-limited function throws. If provided, the handler will be called with the error and rate limiter instance. This can be used alongside throwOnError - the handler will be called before any error is thrown.
unknown
AsyncRateLimiter<TFn>
void
optional onReject: (rateLimiter) => void;
optional onReject: (rateLimiter) => void;
Defined in: async-rate-limiter.ts:28
Optional callback function that is called when an execution is rejected due to rate limiting
AsyncRateLimiter<TFn>
void
optional onSettled: (rateLimiter) => void;
optional onSettled: (rateLimiter) => void;
Defined in: async-rate-limiter.ts:32
Optional function to call when the rate-limited function is executed
AsyncRateLimiter<TFn>
void
optional onSuccess: (result, rateLimiter) => void;
optional onSuccess: (result, rateLimiter) => void;
Defined in: async-rate-limiter.ts:36
Optional function to call when the rate-limited function is executed
ReturnType<TFn>
AsyncRateLimiter<TFn>
void
optional throwOnError: boolean;
optional throwOnError: boolean;
Defined in: async-rate-limiter.ts:45
Whether to throw errors when they occur. Defaults to true if no onError handler is provided, false if an onError handler is provided. Can be explicitly set to override these defaults.
window: number | (rateLimiter) => number;
window: number | (rateLimiter) => number;
Defined in: async-rate-limiter.ts:50
Time window in milliseconds within which the limit applies. Can be a number or a function that returns a number.
optional windowType: "fixed" | "sliding";
optional windowType: "fixed" | "sliding";
Defined in: async-rate-limiter.ts:57
Type of window to use for rate limiting
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.