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

AsyncRetryerOptions.md

420 lines7.5 KB

1---
2id: AsyncRetryerOptions
3title: AsyncRetryerOptions
4---
5​
6Defined in: [async-retryer.ts:59](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-retryer.ts#L59)
7​
8## Type Parameters
9​
10### TFn
11​
12`TFn` *extends* [`AnyAsyncFunction`](../type-aliases/AnyAsyncFunction.md)
13​
14## Properties
15​
16### backoff?
17​
18```ts
19optional backoff?: "linear" | "exponential" | "fixed";
20```
21​
22Defined in: [async-retryer.ts:67](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-retryer.ts#L67)
23​
24The backoff strategy for retry delays:
25- 'exponential': Wait time doubles with each attempt (1s, 2s, 4s, ...)
26- 'linear': Wait time increases linearly (1s, 2s, 3s, ...)
27- 'fixed': Same wait time for all attempts
28​
29#### Default
30​
31```ts
32'exponential'
33```
34​
35***
36​
37### baseWait?
38​
39```ts
40optional baseWait?: number | ((retryer) => number);
41```
42​
43Defined in: [async-retryer.ts:72](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-retryer.ts#L72)
44​
45Base wait time in milliseconds between retries, or a function that returns the wait time
46​
47#### Default
48​
49```ts
501000
51```
52​
53***
54​
55### enabled?
56​
57```ts
58optional enabled?: boolean | ((retryer) => boolean);
59```
60​
61Defined in: [async-retryer.ts:77](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-retryer.ts#L77)
62​
63Whether the retryer is enabled, or a function that determines if it's enabled
64​
65#### Default
66​
67```ts
68true
69```
70​
71***
72​
73### initialState?
74​
75```ts
76optional initialState?: Partial<AsyncRetryerState<TFn>>;
77```
78​
79Defined in: [async-retryer.ts:81](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-retryer.ts#L81)
80​
81Initial state to merge with the default state
82​
83***
84​
85### jitter?
86​
87```ts
88optional jitter?: number;
89```
90​
91Defined in: [async-retryer.ts:86](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-retryer.ts#L86)
92​
93Jitter percentage to add to retry delays (0-1). Adds randomness to prevent thundering herd.
94​
95#### Default
96​
97```ts
99```
100​
101***
102​
103### key?
104​
105```ts
106optional key?: string;
107```
108​
109Defined in: [async-retryer.ts:94](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-retryer.ts#L94)
110​
111Optional key to identify this async retryer instance.
112Note: async retryers are not currently surfaced in the devtools, so this key
113is only a plain identifier. Retryer instances are often created per-execution
114(including internally by the other async utilities), so they intentionally do
115not register with the devtools event bus.
116​
117***
118​
119### maxAttempts?
120​
121```ts
122optional maxAttempts?: number | ((retryer) => number);
123```
124​
125Defined in: [async-retryer.ts:99](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-retryer.ts#L99)
126​
127Maximum number of retry attempts, or a function that returns the max attempts
128​
129#### Default
130​
131```ts
133```
134​
135***
136​
137### maxExecutionTime?
138​
139```ts
140optional maxExecutionTime?: number;
141```
142​
143Defined in: [async-retryer.ts:104](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-retryer.ts#L104)
144​
145Maximum execution time in milliseconds for a single function call before aborting
146​
147#### Default
148​
149```ts
150Infinity
151```
152​
153***
154​
155### maxTotalExecutionTime?
156​
157```ts
158optional maxTotalExecutionTime?: number;
159```
160​
161Defined in: [async-retryer.ts:109](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-retryer.ts#L109)
162​
163Maximum total execution time in milliseconds for the entire retry operation before aborting
164​
165#### Default
166​
167```ts
168Infinity
169```
170​
171***
172​
173### maxWait?
174​
175```ts
176optional maxWait?: number | ((retryer) => number);
177```
178​
179Defined in: [async-retryer.ts:114](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-retryer.ts#L114)
180​
181Maximum wait time in milliseconds to cap retry delays, or a function that returns the max wait time
182​
183#### Default
184​
185```ts
186Infinity
187```
188​
189***
190​
191### onAbort?
192​
193```ts
194optional onAbort?: (reason, retryer) => void;
195```
196​
197Defined in: [async-retryer.ts:118](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-retryer.ts#L118)
198​
199Callback invoked when the execution is aborted (manually or due to timeouts)
200​
201#### Parameters
202​
203##### reason
204​
205`"manual"` \| `"execution-timeout"` \| `"total-timeout"` \| `"new-execution"`
206​
207##### retryer
208​
209[`AsyncRetryer`](../classes/AsyncRetryer.md)\<`TFn`\>
210​
211#### Returns
212​
213`void`
214​
215***
216​
217### onError?
218​
219```ts
220optional onError?: (error, args, retryer) => void;
221```
222​
223Defined in: [async-retryer.ts:125](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-retryer.ts#L125)
224​
225Callback invoked when any error occurs during execution (including retries)
226​
227#### Parameters
228​
229##### error
230​
231`Error`
232​
233##### args
234​
235`Parameters`\<`TFn`\>
236​
237##### retryer
238​
239[`AsyncRetryer`](../classes/AsyncRetryer.md)\<`TFn`\>
240​
241#### Returns
242​
243`void`
244​
245***
246​
247### onExecutionTimeout?
248​
249```ts
250optional onExecutionTimeout?: (retryer) => void;
251```
252​
253Defined in: [async-retryer.ts:133](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-retryer.ts#L133)
254​
255Callback invoked when a single execution attempt times out (maxExecutionTime exceeded)
256​
257#### Parameters
258​
259##### retryer
260​
261[`AsyncRetryer`](../classes/AsyncRetryer.md)\<`TFn`\>
262​
263#### Returns
264​
265`void`
266​
267***
268​
269### onLastError?
270​
271```ts
272optional onLastError?: (error, retryer) => void;
273```
274​
275Defined in: [async-retryer.ts:137](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-retryer.ts#L137)
276​
277Callback invoked when the final error occurs after all retries are exhausted
278​
279#### Parameters
280​
281##### error
282​
283`Error`
284​
285##### retryer
286​
287[`AsyncRetryer`](../classes/AsyncRetryer.md)\<`TFn`\>
288​
289#### Returns
290​
291`void`
292​
293***
294​
295### onRetry?
296​
297```ts
298optional onRetry?: (attempt, error, retryer) => void;
299```
300​
301Defined in: [async-retryer.ts:141](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-retryer.ts#L141)
302​
303Callback invoked before each retry attempt
304​
305#### Parameters
306​
307##### attempt
308​
309`number`
310​
311##### error
312​
313`Error`
314​
315##### retryer
316​
317[`AsyncRetryer`](../classes/AsyncRetryer.md)\<`TFn`\>
318​
319#### Returns
320​
321`void`
322​
323***
324​
325### onSettled?
326​
327```ts
328optional onSettled?: (args, retryer) => void;
329```
330​
331Defined in: [async-retryer.ts:145](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-retryer.ts#L145)
332​
333Callback invoked after execution completes (success or failure) of each attempt
334​
335#### Parameters
336​
337##### args
338​
339`Parameters`\<`TFn`\>
340​
341##### retryer
342​
343[`AsyncRetryer`](../classes/AsyncRetryer.md)\<`TFn`\>
344​
345#### Returns
346​
347`void`
348​
349***
350​
351### onSuccess?
352​
353```ts
354optional onSuccess?: (result, args, retryer) => void;
355```
356​
357Defined in: [async-retryer.ts:149](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-retryer.ts#L149)
358​
359Callback invoked when execution succeeds
360​
361#### Parameters
362​
363##### result
364​
365`Awaited`\<`ReturnType`\<`TFn`\>\>
366​
367##### args
368​
369`Parameters`\<`TFn`\>
370​
371##### retryer
372​
373[`AsyncRetryer`](../classes/AsyncRetryer.md)\<`TFn`\>
374​
375#### Returns
376​
377`void`
378​
379***
380​
381### onTotalExecutionTimeout?
382​
383```ts
384optional onTotalExecutionTimeout?: (retryer) => void;
385```
386​
387Defined in: [async-retryer.ts:157](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-retryer.ts#L157)
388​
389Callback invoked when the total execution time times out (maxTotalExecutionTime exceeded)
390​
391#### Parameters
392​
393##### retryer
394​
395[`AsyncRetryer`](../classes/AsyncRetryer.md)\<`TFn`\>
396​
397#### Returns
398​
399`void`
400​
401***
402​
403### throwOnError?
404​
405```ts
406optional throwOnError?: boolean | "last";
407```
408​
409Defined in: [async-retryer.ts:165](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-retryer.ts#L165)
410​
411Controls when errors are thrown:
412- 'last': Only throw the final error after all retries are exhausted
413- true: Throw every error immediately (disables retrying)
414- false: Never throw errors, return undefined instead
415​
416#### Default
417​
418```ts
419'last'
420```