Framework
Version
防抖器 API 參考
節流器 API 參考
速率限制器 API 參考
佇列 API 參考

AsyncRateLimiterOptions

Interface: AsyncRateLimiterOptions<TFn>

Defined in: async-rate-limiter.ts:6

Options for configuring an async rate-limited function

Type Parameters

TFn extends AnyAsyncFunction

Properties

enabled?

ts
optional enabled: boolean;
optional enabled: boolean;

Defined in: async-rate-limiter.ts:11

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


limit

ts
limit: number;
limit: number;

Defined in: async-rate-limiter.ts:15

Maximum number of executions allowed within the time window


onError()?

ts
optional onError: (error, rateLimiter) => void;
optional onError: (error, rateLimiter) => void;

Defined in: async-rate-limiter.ts:19

Optional error handler for when the rate-limited function throws

Parameters

error

unknown

rateLimiter

AsyncRateLimiter<TFn>

Returns

void


onReject()?

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

Defined in: async-rate-limiter.ts:34

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

Parameters

rateLimiter

AsyncRateLimiter<TFn>

Returns

void


onSettled()?

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

Defined in: async-rate-limiter.ts:23

Optional function to call when the rate-limited function is executed

Parameters

rateLimiter

AsyncRateLimiter<TFn>

Returns

void


onSuccess()?

ts
optional onSuccess: (result, rateLimiter) => void;
optional onSuccess: (result, rateLimiter) => void;

Defined in: async-rate-limiter.ts:27

Optional function to call when the rate-limited function is executed

Parameters

result

ReturnType<TFn>

rateLimiter

AsyncRateLimiter<TFn>

Returns

void


window

ts
window: number;
window: number;

Defined in: async-rate-limiter.ts:38

Time window in milliseconds within which the limit applies

Subscribe to Bytes

Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.

Bytes

No spam. Unsubscribe at any time.