Framework
Version
Debouncer API Reference
Throttler API Reference
Rate Limiter API Reference
Queue API Reference
Batcher API Reference

RateLimiterOptions

Interface: RateLimiterOptions<TFn>

Defined in: rate-limiter.ts:41

Options for configuring a rate-limited function

Type Parameters

TFn extends AnyFunction

Properties

enabled?

ts
optional enabled: boolean | (rateLimiter) => boolean;
optional enabled: boolean | (rateLimiter) => boolean;

Defined in: rate-limiter.ts:46

Whether the rate limiter is enabled. When disabled, maybeExecute will not trigger any executions. Defaults to true.


initialState?

ts
optional initialState: Partial<RateLimiterState>;
optional initialState: Partial<RateLimiterState>;

Defined in: rate-limiter.ts:50

Initial state for the rate limiter


limit

ts
limit: number | (rateLimiter) => number;
limit: number | (rateLimiter) => number;

Defined in: rate-limiter.ts:55

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.


onExecute()?

ts
optional onExecute: (args, rateLimiter) => void;
optional onExecute: (args, rateLimiter) => void;

Defined in: rate-limiter.ts:59

Callback function that is called after the function is executed

Parameters

args

Parameters<TFn>

rateLimiter

RateLimiter<TFn>

Returns

void


onReject()?

ts
optional onReject: (rateLimiter) => void;
optional onReject: (rateLimiter) => void;

Defined in: rate-limiter.ts:63

Optional callback function that is called when an execution is rejected due to rate limiting

Parameters

rateLimiter

RateLimiter<TFn>

Returns

void


window

ts
window: number | (rateLimiter) => number;
window: number | (rateLimiter) => number;

Defined in: rate-limiter.ts:68

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.


windowType?

ts
optional windowType: "fixed" | "sliding";
optional windowType: "fixed" | "sliding";

Defined in: rate-limiter.ts:75

Type of window to use for rate limiting

  • 'fixed': Uses a fixed window that resets after the window period
  • 'sliding': Uses a sliding window that allows executions as old ones expire Defaults to 'fixed'