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

AsyncThrottlerOptions.md

207 lines4.3 KB

1---
2id: AsyncThrottlerOptions
3title: AsyncThrottlerOptions
4---
5​
6Defined in: [async-throttler.ts:76](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-throttler.ts#L76)
7​
8Options for configuring an async throttled 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-throttler.ts:80](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-throttler.ts#L80)
25​
26Options for configuring the underlying async retryer
27​
28***
29​
30### enabled?
31​
32```ts
33optional enabled?: boolean | ((throttler) => boolean);
34```
35​
36Defined in: [async-throttler.ts:86](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-throttler.ts#L86)
37​
38Whether the throttler 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<AsyncThrottlerState<TFn>>;
48```
49​
50Defined in: [async-throttler.ts:90](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-throttler.ts#L90)
51​
52Initial state for the async throttler
53​
54***
55​
56### key?
57​
58```ts
59optional key?: string;
60```
61​
62Defined in: [async-throttler.ts:95](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-throttler.ts#L95)
63​
64Optional key to identify this async throttler instance.
65If provided, the async throttler will be identified by this key in the devtools and PacerProvider if applicable.
66​
67***
68​
69### leading?
70​
71```ts
72optional leading?: boolean;
73```
74​
75Defined in: [async-throttler.ts:100](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-throttler.ts#L100)
76​
77Whether to execute the function immediately when called
78Defaults to true
79​
80***
81​
82### onError?
83​
84```ts
85optional onError?: (error, args, asyncThrottler) => void;
86```
87​
88Defined in: [async-throttler.ts:106](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-throttler.ts#L106)
89​
90Optional error handler for when the throttled function throws.
91If provided, the handler will be called with the error and throttler 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##### asyncThrottler
105​
106[`AsyncThrottler`](../classes/AsyncThrottler.md)\<`TFn`\>
107​
108#### Returns
109​
110`void`
111​
112***
113​
114### onSettled?
115​
116```ts
117optional onSettled?: (args, asyncThrottler) => void;
118```
119​
120Defined in: [async-throttler.ts:114](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-throttler.ts#L114)
121​
122Optional function to call when the throttled function is executed
123​
124#### Parameters
125​
126##### args
127​
128`Parameters`\<`TFn`\>
129​
130##### asyncThrottler
131​
132[`AsyncThrottler`](../classes/AsyncThrottler.md)\<`TFn`\>
133​
134#### Returns
135​
136`void`
137​
138***
139​
140### onSuccess?
141​
142```ts
143optional onSuccess?: (result, args, asyncThrottler) => void;
144```
145​
146Defined in: [async-throttler.ts:121](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-throttler.ts#L121)
147​
148Optional function to call when the throttled function is executed
149​
150#### Parameters
151​
152##### result
153​
154`Awaited`\<`ReturnType`\<`TFn`\>\>
155​
156##### args
157​
158`Parameters`\<`TFn`\>
159​
160##### asyncThrottler
161​
162[`AsyncThrottler`](../classes/AsyncThrottler.md)\<`TFn`\>
163​
164#### Returns
165​
166`void`
167​
168***
169​
170### throwOnError?
171​
172```ts
173optional throwOnError?: boolean;
174```
175​
176Defined in: [async-throttler.ts:131](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-throttler.ts#L131)
177​
178Whether to throw errors when they occur.
179Defaults to true if no onError handler is provided, false if an onError handler is provided.
180Can be explicitly set to override these defaults.
181​
182***
183​
184### trailing?
185​
186```ts
187optional trailing?: boolean;
188```
189​
190Defined in: [async-throttler.ts:136](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-throttler.ts#L136)
191​
192Whether to execute the function on the trailing edge of the wait period
193Defaults to true
194​
195***
196​
197### wait
198​
199```ts
200wait: number | ((throttler) => number);
201```
202​
203Defined in: [async-throttler.ts:142](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-throttler.ts#L142)
204​
205Time window in milliseconds during which the function can only be executed once.
206Can be a number or a function that returns a number.
207Defaults to 0ms