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

AsyncBatcherOptions.md

258 lines4.7 KB

1---
2id: AsyncBatcherOptions
3title: AsyncBatcherOptions
4---
5​
6Defined in: [async-batcher.ts:89](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-batcher.ts#L89)
7​
8Options for configuring an AsyncBatcher instance
9​
10## Type Parameters
11​
12### TValue
13​
14`TValue`
15​
16## Properties
17​
18### asyncRetryerOptions?
19​
20```ts
21optional asyncRetryerOptions?: AsyncRetryerOptions<(items) => Promise<any>>;
22```
23​
24Defined in: [async-batcher.ts:93](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-batcher.ts#L93)
25​
26Options for configuring the underlying async retryer
27​
28***
29​
30### getShouldExecute?
31​
32```ts
33optional getShouldExecute?: (items, batcher) => boolean;
34```
35​
36Defined in: [async-batcher.ts:100](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-batcher.ts#L100)
37​
38Custom function to determine if a batch should be processed
39Return true to process the batch immediately
40​
41#### Parameters
42​
43##### items
44​
45`TValue`[]
46​
47##### batcher
48​
49[`AsyncBatcher`](../classes/AsyncBatcher.md)\<`TValue`\>
50​
51#### Returns
52​
53`boolean`
54​
55***
56​
57### initialState?
58​
59```ts
60optional initialState?: Partial<AsyncBatcherState<TValue>>;
61```
62​
63Defined in: [async-batcher.ts:107](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-batcher.ts#L107)
64​
65Initial state for the async batcher
66​
67***
68​
69### key?
70​
71```ts
72optional key?: string;
73```
74​
75Defined in: [async-batcher.ts:112](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-batcher.ts#L112)
76​
77Optional key to identify this async batcher instance.
78If provided, the async batcher will be identified by this key in the devtools and PacerProvider if applicable.
79​
80***
81​
82### maxSize?
83​
84```ts
85optional maxSize?: number;
86```
87​
88Defined in: [async-batcher.ts:117](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-batcher.ts#L117)
89​
90Maximum number of items in a batch
91​
92#### Default
93​
94```ts
95Infinity
96```
97​
98***
99​
100### onError?
101​
102```ts
103optional onError?: (error, batch, batcher) => void;
104```
105​
106Defined in: [async-batcher.ts:123](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-batcher.ts#L123)
107​
108Optional error handler for when the batch function throws.
109If provided, the handler will be called with the error, the batch of items that failed, and batcher instance.
110This can be used alongside throwOnError - the handler will be called before any error is thrown.
111​
112#### Parameters
113​
114##### error
115​
116`Error`
117​
118##### batch
119​
120`TValue`[]
121​
122##### batcher
123​
124[`AsyncBatcher`](../classes/AsyncBatcher.md)\<`TValue`\>
125​
126#### Returns
127​
128`void`
129​
130***
131​
132### onItemsChange?
133​
134```ts
135optional onItemsChange?: (batcher) => void;
136```
137​
138Defined in: [async-batcher.ts:131](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-batcher.ts#L131)
139​
140Callback fired after items are added to the batcher
141​
142#### Parameters
143​
144##### batcher
145​
146[`AsyncBatcher`](../classes/AsyncBatcher.md)\<`TValue`\>
147​
148#### Returns
149​
150`void`
151​
152***
153​
154### onSettled?
155​
156```ts
157optional onSettled?: (batch, batcher) => void;
158```
159​
160Defined in: [async-batcher.ts:135](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-batcher.ts#L135)
161​
162Optional callback to call when a batch is settled (completed or failed)
163​
164#### Parameters
165​
166##### batch
167​
168`TValue`[]
169​
170##### batcher
171​
172[`AsyncBatcher`](../classes/AsyncBatcher.md)\<`TValue`\>
173​
174#### Returns
175​
176`void`
177​
178***
179​
180### onSuccess?
181​
182```ts
183optional onSuccess?: (result, batch, batcher) => void;
184```
185​
186Defined in: [async-batcher.ts:139](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-batcher.ts#L139)
187​
188Optional callback to call when a batch succeeds
189​
190#### Parameters
191​
192##### result
193​
194`any`
195​
196##### batch
197​
198`TValue`[]
199​
200##### batcher
201​
202[`AsyncBatcher`](../classes/AsyncBatcher.md)\<`TValue`\>
203​
204#### Returns
205​
206`void`
207​
208***
209​
210### started?
211​
212```ts
213optional started?: boolean;
214```
215​
216Defined in: [async-batcher.ts:148](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-batcher.ts#L148)
217​
218Whether the batcher should start processing immediately
219​
220#### Default
221​
222```ts
223true
224```
225​
226***
227​
228### throwOnError?
229​
230```ts
231optional throwOnError?: boolean;
232```
233​
234Defined in: [async-batcher.ts:154](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-batcher.ts#L154)
235​
236Whether to throw errors when they occur.
237Defaults to true if no onError handler is provided, false if an onError handler is provided.
238Can be explicitly set to override these defaults.
239​
240***
241​
242### wait?
243​
244```ts
245optional wait?: number | ((asyncBatcher) => number);
246```
247​
248Defined in: [async-batcher.ts:161](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-batcher.ts#L161)
249​
250Maximum time in milliseconds to wait before processing a batch.
251If the wait duration has elapsed, the batch will be processed.
252If not provided, the batch will not be triggered by a timeout.
253​
254#### Default
255​
256```ts
257Infinity
258```