Skip to content
Source
Sign inSign up
TanStack/pacer
Open History to see the last commit

AsyncRateLimiterOptions.md

234 lines5.0 KB

1---
2id: AsyncRateLimiterOptions
3title: AsyncRateLimiterOptions
4---
5​
6Defined in: [async-rate-limiter.ts:71](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-rate-limiter.ts#L71)
7​
8Options for configuring an async rate-limited function
9​
10## Type Parameters
11​
12### TFn
13​
14`TFn` *extends* [`AnyAsyncFunction`](../type-aliases/AnyAsyncFunction.md)
15​
16## Properties
17​
18### asyncRetryerOptions?
19​
20```ts
21optional asyncRetryerOptions?: AsyncRetryerOptions<TFn>;
22```
23​
24Defined in: [async-rate-limiter.ts:75](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-rate-limiter.ts#L75)
25​
26Options for configuring the underlying async retryer
27​
28***
29​
30### enabled?
31​
32```ts
33optional enabled?: boolean | ((rateLimiter) => boolean);
34```
35​
36Defined in: [async-rate-limiter.ts:81](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-rate-limiter.ts#L81)
37​
38Whether the rate limiter is enabled. When disabled, maybeExecute will not trigger any executions.
39Can be a boolean or a function that returns a boolean.
40Defaults to true.
41​
42***
43​
44### initialState?
45​
46```ts
47optional initialState?: Partial<AsyncRateLimiterState<TFn>>;
48```
49​
50Defined in: [async-rate-limiter.ts:85](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-rate-limiter.ts#L85)
51​
52Initial state for the rate limiter
53​
54***
55​
56### key?
57​
58```ts
59optional key?: string;
60```
61​
62Defined in: [async-rate-limiter.ts:90](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-rate-limiter.ts#L90)
63​
64Optional key to identify this async rate limiter instance.
65If provided, the async rate limiter will be identified by this key in the devtools and PacerProvider if applicable.
66​
67***
68​
69### limit
70​
71```ts
72limit: number | ((rateLimiter) => number);
73```
74​
75Defined in: [async-rate-limiter.ts:95](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-rate-limiter.ts#L95)
76​
77Maximum number of executions allowed within the time window.
78Can be a number or a function that returns a number.
79​
80***
81​
82### onError?
83​
84```ts
85optional onError?: (error, args, rateLimiter) => void;
86```
87​
88Defined in: [async-rate-limiter.ts:101](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-rate-limiter.ts#L101)
89​
90Optional error handler for when the rate-limited function throws.
91If provided, the handler will be called with the error and rate limiter instance.
92This can be used alongside throwOnError - the handler will be called before any error is thrown.
93​
94#### Parameters
95​
96##### error
97​
98`Error`
99​
100##### args
101​
102`Parameters`\<`TFn`\>
103​
104##### rateLimiter
105​
106[`AsyncRateLimiter`](../classes/AsyncRateLimiter.md)\<`TFn`\>
107​
108#### Returns
109​
110`void`
111​
112***
113​
114### onReject?
115​
116```ts
117optional onReject?: (args, rateLimiter) => void;
118```
119​
120Defined in: [async-rate-limiter.ts:109](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-rate-limiter.ts#L109)
121​
122Optional callback function that is called when an execution is rejected due to rate limiting
123​
124#### Parameters
125​
126##### args
127​
128`Parameters`\<`TFn`\>
129​
130##### rateLimiter
131​
132[`AsyncRateLimiter`](../classes/AsyncRateLimiter.md)\<`TFn`\>
133​
134#### Returns
135​
136`void`
137​
138***
139​
140### onSettled?
141​
142```ts
143optional onSettled?: (args, rateLimiter) => void;
144```
145​
146Defined in: [async-rate-limiter.ts:113](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-rate-limiter.ts#L113)
147​
148Optional function to call when the rate-limited function is executed
149​
150#### Parameters
151​
152##### args
153​
154`Parameters`\<`TFn`\>
155​
156##### rateLimiter
157​
158[`AsyncRateLimiter`](../classes/AsyncRateLimiter.md)\<`TFn`\>
159​
160#### Returns
161​
162`void`
163​
164***
165​
166### onSuccess?
167​
168```ts
169optional onSuccess?: (result, args, rateLimiter) => void;
170```
171​
172Defined in: [async-rate-limiter.ts:120](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-rate-limiter.ts#L120)
173​
174Optional function to call when the rate-limited function is executed
175​
176#### Parameters
177​
178##### result
179​
180`Awaited`\<`ReturnType`\<`TFn`\>\>
181​
182##### args
183​
184`Parameters`\<`TFn`\>
185​
186##### rateLimiter
187​
188[`AsyncRateLimiter`](../classes/AsyncRateLimiter.md)\<`TFn`\>
189​
190#### Returns
191​
192`void`
193​
194***
195​
196### throwOnError?
197​
198```ts
199optional throwOnError?: boolean;
200```
201​
202Defined in: [async-rate-limiter.ts:130](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-rate-limiter.ts#L130)
203​
204Whether to throw errors when they occur.
205Defaults to true if no onError handler is provided, false if an onError handler is provided.
206Can be explicitly set to override these defaults.
207​
208***
209​
210### window
211​
212```ts
213window: number | ((rateLimiter) => number);
214```
215​
216Defined in: [async-rate-limiter.ts:135](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-rate-limiter.ts#L135)
217​
218Time window in milliseconds within which the limit applies.
219Can be a number or a function that returns a number.
220​
221***
222​
223### windowType?
224​
225```ts
226optional windowType?: "fixed" | "sliding";
227```
228​
229Defined in: [async-rate-limiter.ts:142](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-rate-limiter.ts#L142)
230​
231Type of window to use for rate limiting
232- 'fixed': Uses a fixed window that resets after the window period
233- 'sliding': Uses a sliding window that allows executions as old ones expire
234Defaults to 'fixed'