Skip to content

Commit 98e606f

Browse files
fix: getAbortSignal binding, async-queuer last result (#132)
* fix: getAbortSignal binding, async-queuer last result * ci: apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 6f8772d commit 98e606f

15 files changed

+137
-24
lines changed

.changeset/every-badgers-jog.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@tanstack/pacer': patch
3+
'@tanstack/pacer-devtools': patch
4+
'@tanstack/preact-pacer': patch
5+
'@tanstack/preact-pacer-devtools': patch
6+
'@tanstack/react-pacer': patch
7+
'@tanstack/react-pacer-devtools': patch
8+
'@tanstack/solid-pacer': patch
9+
'@tanstack/solid-pacer-devtools': patch
10+
---
11+
12+
Fixed getAbortSignal binding on all utils
13+
Fixed lastResult overwrite bug in AsyncQueuer
14+
Updated TanStack Devtools versions

docs/reference/classes/AsyncQueuer.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ Defined in: [async-queuer.ts:316](https://github.com/TanStack/pacer/blob/main/pa
168168
abort(): void;
169169
```
170170

171-
Defined in: [async-queuer.ts:833](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L833)
171+
Defined in: [async-queuer.ts:832](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L832)
172172

173173
Aborts all ongoing executions with the internal abort controllers.
174174
Does NOT clear out the items.
@@ -188,7 +188,7 @@ addItem(
188188
runOnItemsChange): boolean;
189189
```
190190

191-
Defined in: [async-queuer.ts:471](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L471)
191+
Defined in: [async-queuer.ts:470](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L470)
192192

193193
Adds an item to the queue. If the queue is full, the item is rejected and onReject is called.
194194
Items can be inserted based on priority or at the front/back depending on configuration.
@@ -226,7 +226,7 @@ queuer.addItem('task2', 'front');
226226
clear(): void;
227227
```
228228

229-
Defined in: [async-queuer.ts:798](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L798)
229+
Defined in: [async-queuer.ts:797](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L797)
230230

231231
Removes all pending items from the queue.
232232
Does NOT affect active tasks.
@@ -243,7 +243,7 @@ Does NOT affect active tasks.
243243
execute(position?): Promise<any>;
244244
```
245245
246-
Defined in: [async-queuer.ts:606](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L606)
246+
Defined in: [async-queuer.ts:605](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L605)
247247
248248
Removes and returns the next item from the queue and executes the task function with it.
249249
@@ -273,7 +273,7 @@ queuer.execute('back');
273273
flush(numberOfItems, position?): Promise<void>;
274274
```
275275
276-
Defined in: [async-queuer.ts:654](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L654)
276+
Defined in: [async-queuer.ts:653](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L653)
277277
278278
Processes a specified number of items to execute immediately with no wait time
279279
If no numberOfItems is provided, all items will be processed
@@ -300,7 +300,7 @@ If no numberOfItems is provided, all items will be processed
300300
flushAsBatch(batchFunction): Promise<void>;
301301
```
302302
303-
Defined in: [async-queuer.ts:668](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L668)
303+
Defined in: [async-queuer.ts:667](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L667)
304304
305305
Processes all items in the queue as a batch using the provided function as an argument
306306
The queue is cleared after processing
@@ -323,7 +323,7 @@ The queue is cleared after processing
323323
getAbortSignal(executeCount?): AbortSignal | null;
324324
```
325325
326-
Defined in: [async-queuer.ts:823](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L823)
326+
Defined in: [async-queuer.ts:822](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L822)
327327
328328
Returns the AbortSignal for a specific execution.
329329
If no executeCount is provided, returns the signal for the most recent execution.
@@ -364,7 +364,7 @@ const queuer = new AsyncQueuer(
364364
getNextItem(position): TValue | undefined;
365365
```
366366
367-
Defined in: [async-queuer.ts:554](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L554)
367+
Defined in: [async-queuer.ts:553](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L553)
368368
369369
Removes and returns the next item from the queue without executing the task function.
370370
Use for manual queue management. Normally, use execute() to process items.
@@ -396,7 +396,7 @@ queuer.getNextItem('back');
396396
peekActiveItems(): TValue[];
397397
```
398398
399-
Defined in: [async-queuer.ts:760](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L760)
399+
Defined in: [async-queuer.ts:759](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L759)
400400
401401
Returns the items currently being processed (active tasks).
402402
@@ -412,7 +412,7 @@ Returns the items currently being processed (active tasks).
412412
peekAllItems(): TValue[];
413413
```
414414
415-
Defined in: [async-queuer.ts:753](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L753)
415+
Defined in: [async-queuer.ts:752](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L752)
416416
417417
Returns a copy of all items in the queue, including active and pending items.
418418
@@ -428,7 +428,7 @@ Returns a copy of all items in the queue, including active and pending items.
428428
peekNextItem(position): TValue | undefined;
429429
```
430430
431-
Defined in: [async-queuer.ts:743](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L743)
431+
Defined in: [async-queuer.ts:742](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L742)
432432
433433
Returns the next item in the queue without removing it.
434434
@@ -457,7 +457,7 @@ queuer.peekNextItem('back'); // back
457457
peekPendingItems(): TValue[];
458458
```
459459
460-
Defined in: [async-queuer.ts:767](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L767)
460+
Defined in: [async-queuer.ts:766](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L766)
461461
462462
Returns the items waiting to be processed (pending tasks).
463463
@@ -473,7 +473,7 @@ Returns the items waiting to be processed (pending tasks).
473473
reset(): void;
474474
```
475475
476-
Defined in: [async-queuer.ts:844](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L844)
476+
Defined in: [async-queuer.ts:843](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L843)
477477
478478
Resets the queuer state to its default values
479479
@@ -511,7 +511,7 @@ Updates the queuer options. New options are merged with existing options.
511511
start(): void;
512512
```
513513
514-
Defined in: [async-queuer.ts:774](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L774)
514+
Defined in: [async-queuer.ts:773](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L773)
515515
516516
Starts processing items in the queue. If already running, does nothing.
517517
@@ -527,7 +527,7 @@ Starts processing items in the queue. If already running, does nothing.
527527
stop(): void;
528528
```
529529
530-
Defined in: [async-queuer.ts:784](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L784)
530+
Defined in: [async-queuer.ts:783](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L783)
531531
532532
Stops processing items in the queue. Does not clear the queue.
533533

docs/reference/functions/asyncQueue.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ title: asyncQueue
99
function asyncQueue<TValue>(fn, initialOptions): (item, position, runOnItemsChange) => boolean;
1010
```
1111

12-
Defined in: [async-queuer.ts:916](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L916)
12+
Defined in: [async-queuer.ts:915](https://github.com/TanStack/pacer/blob/main/packages/pacer/src/async-queuer.ts#L915)
1313

1414
Creates a new AsyncQueuer instance and returns a bound addItem function for adding tasks.
1515
The queuer is started automatically and ready to process items.

packages/pacer/src/async-batcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ export class AsyncBatcher<TValue> {
476476
* )
477477
* ```
478478
*/
479-
getAbortSignal(executeCount?: number): AbortSignal | null {
479+
getAbortSignal = (executeCount?: number): AbortSignal | null => {
480480
const count = executeCount ?? this.store.state.executeCount
481481
const retryer = this.asyncRetryers.get(count)
482482
return retryer?.getAbortSignal() ?? null

packages/pacer/src/async-debouncer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ export class AsyncDebouncer<TFn extends AnyAsyncFunction> {
452452
* )
453453
* ```
454454
*/
455-
getAbortSignal(maybeExecuteCount?: number): AbortSignal | null {
455+
getAbortSignal = (maybeExecuteCount?: number): AbortSignal | null => {
456456
const count = maybeExecuteCount ?? this.store.state.maybeExecuteCount
457457
const retryer = this.asyncRetryers.get(count)
458458
return retryer?.getAbortSignal() ?? null

packages/pacer/src/async-queuer.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,7 @@ export class AsyncQueuer<TValue> {
441441
activeItems,
442442
})
443443
;(async () => {
444-
const result = await this.execute()
445-
this.#setState({ lastResult: result })
444+
await this.execute()
446445

447446
const wait = this.#getWait()
448447
if (wait > 0) {
@@ -820,7 +819,7 @@ export class AsyncQueuer<TValue> {
820819
* )
821820
* ```
822821
*/
823-
getAbortSignal(executeCount?: number): AbortSignal | null {
822+
getAbortSignal = (executeCount?: number): AbortSignal | null => {
824823
const count = executeCount ?? this.store.state.executeCount
825824
const retryer = this.asyncRetryers.get(count)
826825
return retryer?.getAbortSignal() ?? null

packages/pacer/src/async-rate-limiter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ export class AsyncRateLimiter<TFn extends AnyAsyncFunction> {
522522
* )
523523
* ```
524524
*/
525-
getAbortSignal(maybeExecuteCount?: number): AbortSignal | null {
525+
getAbortSignal = (maybeExecuteCount?: number): AbortSignal | null => {
526526
const count = maybeExecuteCount ?? this.store.state.maybeExecuteCount
527527
const retryer = this.asyncRetryers.get(count)
528528
return retryer?.getAbortSignal() ?? null

packages/pacer/src/async-retryer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ export class AsyncRetryer<TFn extends AnyAsyncFunction> {
594594
* retryer.abort()
595595
* ```
596596
*/
597-
getAbortSignal(): AbortSignal | null {
597+
getAbortSignal = (): AbortSignal | null => {
598598
return this.#abortController?.signal ?? null
599599
}
600600

packages/pacer/src/async-throttler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ export class AsyncThrottler<TFn extends AnyAsyncFunction> {
516516
* )
517517
* ```
518518
*/
519-
getAbortSignal(maybeExecuteCount?: number): AbortSignal | null {
519+
getAbortSignal = (maybeExecuteCount?: number): AbortSignal | null => {
520520
const count = maybeExecuteCount ?? this.store.state.maybeExecuteCount
521521
const retryer = this.asyncRetryers.get(count)
522522
return retryer?.getAbortSignal() ?? null

packages/pacer/tests/async-batcher.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,4 +751,18 @@ describe('asyncBatch', () => {
751751
expect(mockFn).toHaveBeenCalledTimes(1)
752752
expect(mockFn).toHaveBeenCalledWith([1])
753753
})
754+
755+
describe('getAbortSignal', () => {
756+
it('should be available as an instance method', () => {
757+
const batcher = new AsyncBatcher(
758+
async (items) => {
759+
return items
760+
},
761+
{ maxSize: 10, wait: 100 },
762+
)
763+
764+
expect(typeof batcher.getAbortSignal).toBe('function')
765+
expect(batcher.getAbortSignal()).toBeNull()
766+
})
767+
})
754768
})

0 commit comments

Comments
 (0)