Defined in: rate-limiter.ts:31
Options for configuring a rate-limited function
• TFn extends AnyFunction
optional enabled: boolean | (rateLimiter) => boolean;
optional enabled: boolean | (rateLimiter) => boolean;
Defined in: rate-limiter.ts:36
Whether the rate limiter is enabled. When disabled, maybeExecute will not trigger any executions. Defaults to true.
optional initialState: Partial<RateLimiterState>;
optional initialState: Partial<RateLimiterState>;
Defined in: rate-limiter.ts:40
Initial state for the rate limiter
limit: number | (rateLimiter) => number;
limit: number | (rateLimiter) => number;
Defined in: rate-limiter.ts:45
Maximum number of executions allowed within the time window. Can be a number or a callback function that receives the rate limiter instance and returns a number.
optional onExecute: (rateLimiter) => void;
optional onExecute: (rateLimiter) => void;
Defined in: rate-limiter.ts:49
Callback function that is called after the function is executed
RateLimiter<TFn>
void
optional onReject: (rateLimiter) => void;
optional onReject: (rateLimiter) => void;
Defined in: rate-limiter.ts:53
Optional callback function that is called when an execution is rejected due to rate limiting
RateLimiter<TFn>
void
window: number | (rateLimiter) => number;
window: number | (rateLimiter) => number;
Defined in: rate-limiter.ts:58
Time window in milliseconds within which the limit applies. Can be a number or a callback function that receives the rate limiter instance and returns a number.
optional windowType: "fixed" | "sliding";
optional windowType: "fixed" | "sliding";
Defined in: rate-limiter.ts:65
Type of window to use for rate limiting
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.