@tanstack/pacer 0.16.3 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/README.md +165 -0
  2. package/dist/async-batcher.cjs +355 -0
  3. package/dist/async-batcher.cjs.map +1 -0
  4. package/dist/async-batcher.d.cts +344 -0
  5. package/dist/async-batcher.d.ts +344 -0
  6. package/dist/async-batcher.js +353 -0
  7. package/dist/async-batcher.js.map +1 -0
  8. package/dist/async-debouncer.cjs +340 -0
  9. package/dist/async-debouncer.cjs.map +1 -0
  10. package/dist/async-debouncer.d.cts +300 -0
  11. package/dist/async-debouncer.d.ts +300 -0
  12. package/dist/async-debouncer.js +338 -0
  13. package/dist/async-debouncer.js.map +1 -0
  14. package/dist/async-queuer.cjs +496 -0
  15. package/dist/async-queuer.cjs.map +1 -0
  16. package/dist/async-queuer.d.cts +440 -0
  17. package/dist/async-queuer.d.ts +440 -0
  18. package/dist/async-queuer.js +494 -0
  19. package/dist/async-queuer.js.map +1 -0
  20. package/dist/async-rate-limiter.cjs +381 -0
  21. package/dist/async-rate-limiter.cjs.map +1 -0
  22. package/dist/{cjs/async-rate-limiter.d.cts → async-rate-limiter.d.cts} +190 -185
  23. package/dist/{esm/async-rate-limiter.d.ts → async-rate-limiter.d.ts} +190 -185
  24. package/dist/async-rate-limiter.js +379 -0
  25. package/dist/async-rate-limiter.js.map +1 -0
  26. package/dist/async-retryer.cjs +378 -0
  27. package/dist/async-retryer.cjs.map +1 -0
  28. package/dist/async-retryer.d.cts +312 -0
  29. package/dist/async-retryer.d.ts +312 -0
  30. package/dist/async-retryer.js +376 -0
  31. package/dist/async-retryer.js.map +1 -0
  32. package/dist/async-throttler.cjs +362 -0
  33. package/dist/async-throttler.cjs.map +1 -0
  34. package/dist/async-throttler.d.cts +320 -0
  35. package/dist/async-throttler.d.ts +320 -0
  36. package/dist/async-throttler.js +360 -0
  37. package/dist/async-throttler.js.map +1 -0
  38. package/dist/batcher.cjs +194 -0
  39. package/dist/batcher.cjs.map +1 -0
  40. package/dist/batcher.d.cts +180 -0
  41. package/dist/batcher.d.ts +180 -0
  42. package/dist/batcher.js +193 -0
  43. package/dist/batcher.js.map +1 -0
  44. package/dist/debouncer.cjs +197 -0
  45. package/dist/debouncer.cjs.map +1 -0
  46. package/dist/debouncer.d.cts +167 -0
  47. package/dist/debouncer.d.ts +167 -0
  48. package/dist/debouncer.js +195 -0
  49. package/dist/debouncer.js.map +1 -0
  50. package/dist/event-client.cjs +20 -0
  51. package/dist/event-client.cjs.map +1 -0
  52. package/dist/event-client.d.cts +49 -0
  53. package/dist/event-client.d.ts +49 -0
  54. package/dist/event-client.js +19 -0
  55. package/dist/event-client.js.map +1 -0
  56. package/dist/index.cjs +49 -0
  57. package/dist/index.d.cts +15 -0
  58. package/dist/index.d.ts +15 -0
  59. package/dist/{esm/index.js → index.js} +5 -41
  60. package/dist/queuer.cjs +393 -0
  61. package/dist/queuer.cjs.map +1 -0
  62. package/dist/queuer.d.cts +345 -0
  63. package/dist/queuer.d.ts +345 -0
  64. package/dist/queuer.js +391 -0
  65. package/dist/queuer.js.map +1 -0
  66. package/dist/rate-limiter.cjs +251 -0
  67. package/dist/rate-limiter.cjs.map +1 -0
  68. package/dist/{cjs/rate-limiter.d.cts → rate-limiter.d.cts} +113 -108
  69. package/dist/{esm/rate-limiter.d.ts → rate-limiter.d.ts} +113 -108
  70. package/dist/rate-limiter.js +249 -0
  71. package/dist/rate-limiter.js.map +1 -0
  72. package/dist/throttler.cjs +209 -0
  73. package/dist/throttler.cjs.map +1 -0
  74. package/dist/throttler.d.cts +207 -0
  75. package/dist/throttler.d.ts +207 -0
  76. package/dist/throttler.js +207 -0
  77. package/dist/throttler.js.map +1 -0
  78. package/dist/types.cjs +0 -0
  79. package/dist/types.d.cts +13 -0
  80. package/dist/types.d.ts +13 -0
  81. package/dist/types.js +1 -0
  82. package/dist/utils.cjs +13 -0
  83. package/dist/utils.cjs.map +1 -0
  84. package/dist/utils.d.cts +8 -0
  85. package/dist/utils.d.ts +8 -0
  86. package/dist/utils.js +11 -0
  87. package/dist/utils.js.map +1 -0
  88. package/package.json +39 -123
  89. package/dist/cjs/async-batcher.cjs +0 -222
  90. package/dist/cjs/async-batcher.cjs.map +0 -1
  91. package/dist/cjs/async-batcher.d.cts +0 -340
  92. package/dist/cjs/async-debouncer.cjs +0 -233
  93. package/dist/cjs/async-debouncer.cjs.map +0 -1
  94. package/dist/cjs/async-debouncer.d.cts +0 -295
  95. package/dist/cjs/async-queuer.cjs +0 -399
  96. package/dist/cjs/async-queuer.cjs.map +0 -1
  97. package/dist/cjs/async-queuer.d.cts +0 -435
  98. package/dist/cjs/async-rate-limiter.cjs +0 -254
  99. package/dist/cjs/async-rate-limiter.cjs.map +0 -1
  100. package/dist/cjs/async-retryer.cjs +0 -287
  101. package/dist/cjs/async-retryer.cjs.map +0 -1
  102. package/dist/cjs/async-retryer.d.cts +0 -308
  103. package/dist/cjs/async-throttler.cjs +0 -263
  104. package/dist/cjs/async-throttler.cjs.map +0 -1
  105. package/dist/cjs/async-throttler.d.cts +0 -315
  106. package/dist/cjs/batcher.cjs +0 -132
  107. package/dist/cjs/batcher.cjs.map +0 -1
  108. package/dist/cjs/batcher.d.cts +0 -176
  109. package/dist/cjs/debouncer.cjs +0 -139
  110. package/dist/cjs/debouncer.cjs.map +0 -1
  111. package/dist/cjs/debouncer.d.cts +0 -162
  112. package/dist/cjs/event-client.cjs +0 -20
  113. package/dist/cjs/event-client.cjs.map +0 -1
  114. package/dist/cjs/event-client.d.cts +0 -45
  115. package/dist/cjs/index.cjs +0 -51
  116. package/dist/cjs/index.cjs.map +0 -1
  117. package/dist/cjs/index.d.cts +0 -15
  118. package/dist/cjs/queuer.cjs +0 -308
  119. package/dist/cjs/queuer.cjs.map +0 -1
  120. package/dist/cjs/queuer.d.cts +0 -340
  121. package/dist/cjs/rate-limiter.cjs +0 -181
  122. package/dist/cjs/rate-limiter.cjs.map +0 -1
  123. package/dist/cjs/throttler.cjs +0 -153
  124. package/dist/cjs/throttler.cjs.map +0 -1
  125. package/dist/cjs/throttler.d.cts +0 -202
  126. package/dist/cjs/types.d.cts +0 -9
  127. package/dist/cjs/utils.cjs +0 -11
  128. package/dist/cjs/utils.cjs.map +0 -1
  129. package/dist/cjs/utils.d.cts +0 -3
  130. package/dist/esm/async-batcher.d.ts +0 -340
  131. package/dist/esm/async-batcher.js +0 -222
  132. package/dist/esm/async-batcher.js.map +0 -1
  133. package/dist/esm/async-debouncer.d.ts +0 -295
  134. package/dist/esm/async-debouncer.js +0 -233
  135. package/dist/esm/async-debouncer.js.map +0 -1
  136. package/dist/esm/async-queuer.d.ts +0 -435
  137. package/dist/esm/async-queuer.js +0 -399
  138. package/dist/esm/async-queuer.js.map +0 -1
  139. package/dist/esm/async-rate-limiter.js +0 -254
  140. package/dist/esm/async-rate-limiter.js.map +0 -1
  141. package/dist/esm/async-retryer.d.ts +0 -308
  142. package/dist/esm/async-retryer.js +0 -287
  143. package/dist/esm/async-retryer.js.map +0 -1
  144. package/dist/esm/async-throttler.d.ts +0 -315
  145. package/dist/esm/async-throttler.js +0 -263
  146. package/dist/esm/async-throttler.js.map +0 -1
  147. package/dist/esm/batcher.d.ts +0 -176
  148. package/dist/esm/batcher.js +0 -132
  149. package/dist/esm/batcher.js.map +0 -1
  150. package/dist/esm/debouncer.d.ts +0 -162
  151. package/dist/esm/debouncer.js +0 -139
  152. package/dist/esm/debouncer.js.map +0 -1
  153. package/dist/esm/event-client.d.ts +0 -45
  154. package/dist/esm/event-client.js +0 -20
  155. package/dist/esm/event-client.js.map +0 -1
  156. package/dist/esm/index.d.ts +0 -15
  157. package/dist/esm/index.js.map +0 -1
  158. package/dist/esm/queuer.d.ts +0 -340
  159. package/dist/esm/queuer.js +0 -308
  160. package/dist/esm/queuer.js.map +0 -1
  161. package/dist/esm/rate-limiter.js +0 -181
  162. package/dist/esm/rate-limiter.js.map +0 -1
  163. package/dist/esm/throttler.d.ts +0 -202
  164. package/dist/esm/throttler.js +0 -153
  165. package/dist/esm/throttler.js.map +0 -1
  166. package/dist/esm/types.d.ts +0 -9
  167. package/dist/esm/utils.d.ts +0 -3
  168. package/dist/esm/utils.js +0 -11
  169. package/dist/esm/utils.js.map +0 -1
@@ -0,0 +1,440 @@
1
+ import { AsyncRetryer, AsyncRetryerOptions } from "./async-retryer.cjs";
2
+ import { QueuePosition } from "./queuer.cjs";
3
+ import { Store } from "@tanstack/store";
4
+
5
+ //#region src/async-queuer.d.ts
6
+ interface AsyncQueuerState<TValue> {
7
+ /**
8
+ * Items currently being processed by the queuer
9
+ */
10
+ activeItems: Array<TValue>;
11
+ /**
12
+ * Number of times addItem has been called (for reduction calculations)
13
+ */
14
+ addItemCount: number;
15
+ /**
16
+ * Number of task executions that have resulted in errors
17
+ */
18
+ errorCount: number;
19
+ /**
20
+ * Number of times execute has been called
21
+ */
22
+ executeCount: number;
23
+ /**
24
+ * Number of items that have been removed from the queue due to expiration
25
+ */
26
+ expirationCount: number;
27
+ /**
28
+ * Whether the queuer has no items to process (items array is empty)
29
+ */
30
+ isEmpty: boolean;
31
+ /**
32
+ * Whether the queuer is currently executing
33
+ */
34
+ isExecuting: boolean;
35
+ /**
36
+ * Whether the queuer has reached its maximum capacity
37
+ */
38
+ isFull: boolean;
39
+ /**
40
+ * Whether the queuer is not currently processing any items
41
+ */
42
+ isIdle: boolean;
43
+ /**
44
+ * Whether the queuer is active and will process items automatically
45
+ */
46
+ isRunning: boolean;
47
+ /**
48
+ * Array of items currently waiting to be processed
49
+ */
50
+ items: Array<TValue>;
51
+ /**
52
+ * Timestamps when items were added to the queue for expiration tracking
53
+ */
54
+ itemTimestamps: Array<number>;
55
+ /**
56
+ * The result from the most recent task execution
57
+ */
58
+ lastResult: any;
59
+ /**
60
+ * Whether the queuer has a pending timeout for processing the next item
61
+ */
62
+ pendingTick: boolean;
63
+ /**
64
+ * Number of items that have been rejected from being added to the queue
65
+ */
66
+ rejectionCount: number;
67
+ /**
68
+ * Number of task executions that have completed (either successfully or with errors)
69
+ */
70
+ settledCount: number;
71
+ /**
72
+ * Number of items currently in the queue
73
+ */
74
+ size: number;
75
+ /**
76
+ * Current processing status - 'idle' when not processing, 'running' when active, 'stopped' when paused
77
+ */
78
+ status: 'idle' | 'running' | 'stopped';
79
+ /**
80
+ * Number of task executions that have completed successfully
81
+ */
82
+ successCount: number;
83
+ }
84
+ interface AsyncQueuerOptions<TValue> {
85
+ /**
86
+ * Options for configuring the underlying async retryer
87
+ */
88
+ asyncRetryerOptions?: AsyncRetryerOptions<(item: TValue) => Promise<any>>;
89
+ /**
90
+ * Default position to add items to the queuer
91
+ * @default 'back'
92
+ */
93
+ addItemsTo?: QueuePosition;
94
+ /**
95
+ * Maximum number of concurrent tasks to process.
96
+ * Can be a number or a function that returns a number.
97
+ * @default 1
98
+ */
99
+ concurrency?: number | ((queuer: AsyncQueuer<TValue>) => number);
100
+ /**
101
+ * Maximum time in milliseconds that an item can stay in the queue
102
+ * If not provided, items will never expire
103
+ */
104
+ expirationDuration?: number;
105
+ /**
106
+ * Function to determine if an item has expired
107
+ * If provided, this overrides the expirationDuration behavior
108
+ */
109
+ getIsExpired?: (item: TValue, addedAt: number) => boolean;
110
+ /**
111
+ * Default position to get items from during processing
112
+ * @default 'front'
113
+ */
114
+ getItemsFrom?: QueuePosition;
115
+ /**
116
+ * Function to determine priority of items in the queuer
117
+ * Higher priority items will be processed first
118
+ * If not provided, will use static priority values attached to tasks
119
+ */
120
+ getPriority?: (item: TValue) => number;
121
+ /**
122
+ * Initial items to populate the queuer with
123
+ */
124
+ initialItems?: Array<TValue>;
125
+ /**
126
+ * Initial state for the async queuer
127
+ */
128
+ initialState?: Partial<AsyncQueuerState<TValue>>;
129
+ /**
130
+ * Optional key to identify this async queuer instance.
131
+ * If provided, the async queuer will be identified by this key in the devtools and PacerProvider if applicable.
132
+ */
133
+ key?: string;
134
+ /**
135
+ * Maximum number of items allowed in the queuer
136
+ */
137
+ maxSize?: number;
138
+ /**
139
+ * Optional error handler for when a task throws.
140
+ * If provided, the handler will be called with the error and queuer instance.
141
+ * This can be used alongside throwOnError - the handler will be called before any error is thrown.
142
+ */
143
+ onError?: (error: Error, item: TValue, queuer: AsyncQueuer<TValue>) => void;
144
+ /**
145
+ * Callback fired whenever an item expires in the queuer
146
+ */
147
+ onExpire?: (item: TValue, queuer: AsyncQueuer<TValue>) => void;
148
+ /**
149
+ * Callback fired whenever an item is added or removed from the queuer
150
+ */
151
+ onItemsChange?: (queuer: AsyncQueuer<TValue>) => void;
152
+ /**
153
+ * Callback fired whenever an item is rejected from being added to the queuer
154
+ */
155
+ onReject?: (item: TValue, queuer: AsyncQueuer<TValue>) => void;
156
+ /**
157
+ * Optional callback to call when a task is settled
158
+ */
159
+ onSettled?: (item: TValue, queuer: AsyncQueuer<TValue>) => void;
160
+ /**
161
+ * Optional callback to call when a task succeeds
162
+ */
163
+ onSuccess?: (result: any, item: TValue, queuer: AsyncQueuer<TValue>) => void;
164
+ /**
165
+ * Whether the queuer should start processing tasks immediately or not.
166
+ */
167
+ started?: boolean;
168
+ /**
169
+ * Whether to throw errors when they occur.
170
+ * Defaults to true if no onError handler is provided, false if an onError handler is provided.
171
+ * Can be explicitly set to override these defaults.
172
+ */
173
+ throwOnError?: boolean;
174
+ /**
175
+ * Time in milliseconds to wait between processing items.
176
+ * Can be a number or a function that returns a number.
177
+ * @default 0
178
+ */
179
+ wait?: number | ((queuer: AsyncQueuer<TValue>) => number);
180
+ }
181
+ /**
182
+ * Utility function for sharing common `AsyncQueuerOptions` options between different `AsyncQueuer` instances.
183
+ */
184
+ declare function asyncQueuerOptions<TValue = any, TOptions extends Partial<AsyncQueuerOptions<TValue>> = Partial<AsyncQueuerOptions<TValue>>>(options: TOptions): TOptions;
185
+ /**
186
+ * A flexible asynchronous queue for processing tasks with configurable concurrency, priority, and expiration.
187
+ *
188
+ * Async vs Sync Versions:
189
+ * The async version provides advanced features over the sync Queuer:
190
+ * - Returns promises that can be awaited for task results
191
+ * - Built-in retry support via AsyncRetryer integration for each queued task
192
+ * - Abort support to cancel in-flight task executions
193
+ * - Comprehensive error handling with onError callbacks and throwOnError control
194
+ * - Detailed execution tracking (success/error/settle counts)
195
+ * - Concurrent execution support (process multiple items simultaneously)
196
+ *
197
+ * The sync Queuer is lighter weight and simpler when you don't need async features,
198
+ * return values, or execution control.
199
+ *
200
+ * What is Queuing?
201
+ * Queuing is a technique for managing and processing items sequentially or with controlled concurrency.
202
+ * Tasks are processed up to the configured concurrency limit. When a task completes,
203
+ * the next pending task is processed if the concurrency limit allows.
204
+ *
205
+ * Key Features:
206
+ * - Priority queue support via the getPriority option
207
+ * - Configurable concurrency limit
208
+ * - Callbacks for task success, error, completion, and queue state changes
209
+ * - FIFO (First In First Out) or LIFO (Last In First Out) queue behavior
210
+ * - Pause and resume processing
211
+ * - Item expiration to remove stale items from the queue
212
+ *
213
+ * Error Handling:
214
+ * - If an `onError` handler is provided, it will be called with the error and queuer instance
215
+ * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown
216
+ * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed
217
+ * - Both onError and throwOnError can be used together; the handler will be called before any error is thrown
218
+ * - The error state can be checked using the AsyncQueuer instance
219
+ *
220
+ * State Management:
221
+ * - Uses TanStack Store for reactive state management
222
+ * - Use `initialState` to provide initial state values when creating the async queuer
223
+ * - Use `onSuccess` callback to react to successful task execution and implement custom logic
224
+ * - Use `onError` callback to react to task execution errors and implement custom error handling
225
+ * - Use `onSettled` callback to react to task execution completion (success or error) and implement custom logic
226
+ * - Use `onItemsChange` callback to react to items being added or removed from the queue
227
+ * - Use `onExpire` callback to react to items expiring and implement custom logic
228
+ * - Use `onReject` callback to react to items being rejected when the queue is full
229
+ * - The state includes error count, expiration count, rejection count, running status, and success/settle counts
230
+ * - State can be accessed via `asyncQueuer.store.state` when using the class directly
231
+ * - When using framework adapters (React/Solid), state is accessed from `asyncQueuer.state`
232
+ *
233
+ * Example usage:
234
+ * ```ts
235
+ * const asyncQueuer = new AsyncQueuer<string>(async (item) => {
236
+ * // process item
237
+ * return item.toUpperCase();
238
+ * }, {
239
+ * concurrency: 2,
240
+ * onSuccess: (result) => {
241
+ * console.log(result);
242
+ * }
243
+ * });
244
+ *
245
+ * asyncQueuer.addItem('hello');
246
+ * asyncQueuer.start();
247
+ * ```
248
+ */
249
+ declare class AsyncQueuer<TValue> {
250
+ #private;
251
+ fn: (item: TValue) => Promise<any>;
252
+ readonly store: Store<Readonly<AsyncQueuerState<TValue>>>;
253
+ key: string | undefined;
254
+ options: AsyncQueuerOptions<TValue>;
255
+ asyncRetryers: Map<number, AsyncRetryer<(item: TValue) => Promise<any>>>;
256
+ constructor(fn: (item: TValue) => Promise<any>, initialOptions?: AsyncQueuerOptions<TValue>);
257
+ /**
258
+ * Updates the queuer options. New options are merged with existing options.
259
+ */
260
+ setOptions: (newOptions: Partial<AsyncQueuerOptions<TValue>>) => void;
261
+ /**
262
+ * Adds an item to the queue. If the queue is full, the item is rejected and onReject is called.
263
+ * Items can be inserted based on priority or at the front/back depending on configuration.
264
+ *
265
+ * @example
266
+ * ```ts
267
+ * queuer.addItem({ value: 'task', priority: 10 });
268
+ * queuer.addItem('task2', 'front');
269
+ * ```
270
+ */
271
+ addItem: (item: TValue, position?: QueuePosition, runOnItemsChange?: boolean) => boolean;
272
+ /**
273
+ * Removes and returns the next item from the queue without executing the task function.
274
+ * Use for manual queue management. Normally, use execute() to process items.
275
+ *
276
+ * @example
277
+ * ```ts
278
+ * // FIFO
279
+ * queuer.getNextItem();
280
+ * // LIFO
281
+ * queuer.getNextItem('back');
282
+ * ```
283
+ */
284
+ getNextItem: (position?: QueuePosition) => TValue | undefined;
285
+ /**
286
+ * Removes and returns the next item from the queue and executes the task function with it.
287
+ *
288
+ * @example
289
+ * ```ts
290
+ * queuer.execute();
291
+ * // LIFO
292
+ * queuer.execute('back');
293
+ * ```
294
+ */
295
+ execute: (position?: QueuePosition) => Promise<any>;
296
+ /**
297
+ * Processes a specified number of items to execute immediately with no wait time
298
+ * If no numberOfItems is provided, all items will be processed
299
+ */
300
+ flush: (numberOfItems?: number, position?: QueuePosition) => Promise<void>;
301
+ /**
302
+ * Processes all items in the queue as a batch using the provided function as an argument
303
+ * The queue is cleared after processing
304
+ */
305
+ flushAsBatch: (batchFunction: (items: Array<TValue>) => Promise<any>) => Promise<void>;
306
+ /**
307
+ * Returns the next item in the queue without removing it.
308
+ *
309
+ * @example
310
+ * ```ts
311
+ * queuer.peekNextItem(); // front
312
+ * queuer.peekNextItem('back'); // back
313
+ * ```
314
+ */
315
+ peekNextItem: (position?: QueuePosition) => TValue | undefined;
316
+ /**
317
+ * Returns a copy of all items in the queue, including active and pending items.
318
+ */
319
+ peekAllItems: () => Array<TValue>;
320
+ /**
321
+ * Returns the items currently being processed (active tasks).
322
+ */
323
+ peekActiveItems: () => Array<TValue>;
324
+ /**
325
+ * Returns the items waiting to be processed (pending tasks).
326
+ */
327
+ peekPendingItems: () => Array<TValue>;
328
+ /**
329
+ * Starts processing items in the queue. If already running, does nothing.
330
+ */
331
+ start: () => void;
332
+ /**
333
+ * Stops processing items in the queue. Does not clear the queue.
334
+ */
335
+ stop: () => void;
336
+ /**
337
+ * Removes all pending items from the queue.
338
+ * Does NOT affect active tasks.
339
+ */
340
+ clear: () => void;
341
+ /**
342
+ * Returns the AbortSignal for a specific execution.
343
+ * If no executeCount is provided, returns the signal for the most recent execution.
344
+ * Returns null if no execution is found or not currently executing.
345
+ *
346
+ * @param executeCount - Optional specific execution to get signal for
347
+ * @example
348
+ * ```typescript
349
+ * const queuer = new AsyncQueuer(
350
+ * async (item: string) => {
351
+ * const signal = queuer.getAbortSignal()
352
+ * if (signal) {
353
+ * const response = await fetch(`/api/process/${item}`, { signal })
354
+ * return response.json()
355
+ * }
356
+ * },
357
+ * { concurrency: 2 }
358
+ * )
359
+ * ```
360
+ */
361
+ getAbortSignal(executeCount?: number): AbortSignal | null;
362
+ /**
363
+ * Aborts all ongoing executions with the internal abort controllers.
364
+ * Does NOT clear out the items.
365
+ */
366
+ abort: () => void;
367
+ /**
368
+ * Resets the queuer state to its default values
369
+ */
370
+ reset: () => void;
371
+ }
372
+ /**
373
+ * Creates a new AsyncQueuer instance and returns a bound addItem function for adding tasks.
374
+ * The queuer is started automatically and ready to process items.
375
+ *
376
+ * Async vs Sync Versions:
377
+ * The async version provides advanced features over the sync queue function:
378
+ * - Returns promises that can be awaited for task results
379
+ * - Built-in retry support via AsyncRetryer integration for each queued task
380
+ * - Abort support to cancel in-flight task executions
381
+ * - Comprehensive error handling with onError callbacks and throwOnError control
382
+ * - Detailed execution tracking (success/error/settle counts)
383
+ * - Concurrent execution support (process multiple items simultaneously)
384
+ *
385
+ * The sync queue function is lighter weight and simpler when you don't need async features,
386
+ * return values, or execution control.
387
+ *
388
+ * What is Queuing?
389
+ * Queuing is a technique for managing and processing items sequentially or with controlled concurrency.
390
+ * Tasks are processed up to the configured concurrency limit. When a task completes,
391
+ * the next pending task is processed if the concurrency limit allows.
392
+ *
393
+ * Configuration Options:
394
+ * - `concurrency`: Maximum number of concurrent tasks (default: 1)
395
+ * - `wait`: Time to wait between processing items (default: 0)
396
+ * - `maxSize`: Maximum number of items allowed in the queue (default: Infinity)
397
+ * - `getPriority`: Function to determine item priority
398
+ * - `addItemsTo`: Default position to add items ('back' or 'front', default: 'back')
399
+ * - `getItemsFrom`: Default position to get items ('front' or 'back', default: 'front')
400
+ * - `expirationDuration`: Maximum time items can stay in queue
401
+ * - `started`: Whether to start processing immediately (default: true)
402
+ * - `asyncRetryerOptions`: Configure retry behavior for task executions
403
+ *
404
+ * Error Handling:
405
+ * - If an `onError` handler is provided, it will be called with the error and queuer instance
406
+ * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown
407
+ * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed
408
+ * - Both onError and throwOnError can be used together; the handler will be called before any error is thrown
409
+ * - The error state can be checked using the underlying AsyncQueuer instance
410
+ *
411
+ * State Management:
412
+ * - Uses TanStack Store for reactive state management
413
+ * - Use `initialState` to provide initial state values when creating the async queuer
414
+ * - Use `onSuccess` callback to react to successful task execution and implement custom logic
415
+ * - Use `onError` callback to react to task execution errors and implement custom error handling
416
+ * - Use `onSettled` callback to react to task execution completion (success or error) and implement custom logic
417
+ * - Use `onItemsChange` callback to react to items being added or removed from the queue
418
+ * - Use `onExpire` callback to react to items expiring and implement custom logic
419
+ * - Use `onReject` callback to react to items being rejected when the queue is full
420
+ * - The state includes error count, expiration count, rejection count, running status, and success/settle counts
421
+ * - State can be accessed via the underlying AsyncQueuer instance's `store.state` property
422
+ * - When using framework adapters (React/Solid), state is accessed from the hook's state property
423
+ *
424
+ * @example
425
+ * ```ts
426
+ * const enqueue = asyncQueue<string>(async (item) => {
427
+ * return item.toUpperCase();
428
+ * }, {
429
+ * concurrency: 2,
430
+ * wait: 100,
431
+ * onSuccess: (result) => console.log('Processed:', result)
432
+ * });
433
+ *
434
+ * enqueue('hello');
435
+ * ```
436
+ */
437
+ declare function asyncQueue<TValue>(fn: (value: TValue) => Promise<any>, initialOptions: AsyncQueuerOptions<TValue>): (item: TValue, position?: QueuePosition, runOnItemsChange?: boolean) => boolean;
438
+ //#endregion
439
+ export { AsyncQueuer, AsyncQueuerOptions, AsyncQueuerState, asyncQueue, asyncQueuerOptions };
440
+ //# sourceMappingURL=async-queuer.d.cts.map