Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/young-planes-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/pacer': patch
---

fix(async-queuer): Fix falsy item handling in AsyncQueuer#tick — items like 0, "", and false are no longer silently dropped from the processing loop.
2 changes: 1 addition & 1 deletion packages/pacer/src/async-queuer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ export class AsyncQueuer<TValue> {
this.store.state.items.length > 0
) {
const nextItem = this.peekNextItem()
if (!nextItem) {
if (nextItem === undefined) {
break
}
activeItems.push(nextItem)
Expand Down
66 changes: 66 additions & 0 deletions packages/pacer/tests/async-queuer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1095,4 +1095,70 @@ describe('AsyncQueuer', () => {
expect(asyncQueuer.getAbortSignal()).toBeNull()
})
})

describe('falsy item handling', () => {
it('should process items with value 0', async () => {
const processed: Array<number> = []
const asyncQueuer = new AsyncQueuer<number>(
async (item) => {
processed.push(item)
return item
},
{ started: false },
)

asyncQueuer.addItem(0)
asyncQueuer.addItem(1)
asyncQueuer.addItem(2)
asyncQueuer.start()

await vi.advanceTimersByTimeAsync(100)

expect(processed).toEqual([0, 1, 2])
expect(asyncQueuer.store.state.successCount).toBe(3)
})

it('should process items with value "" (empty string)', async () => {
const processed: Array<string> = []
const asyncQueuer = new AsyncQueuer<string>(
async (item) => {
processed.push(item)
return item
},
{ started: false },
)

asyncQueuer.addItem('')
asyncQueuer.addItem('hello')
asyncQueuer.addItem('')
asyncQueuer.start()

await vi.advanceTimersByTimeAsync(100)

expect(processed).toEqual(['', 'hello', ''])
expect(asyncQueuer.store.state.successCount).toBe(3)
})

it('should process items with value false', async () => {
const processed: Array<boolean> = []
const asyncQueuer = new AsyncQueuer<boolean>(
async (item) => {
processed.push(item)
return item
},
{ started: false },
)

asyncQueuer.addItem(false)
asyncQueuer.addItem(true)
asyncQueuer.addItem(false)
asyncQueuer.start()

await vi.advanceTimersByTimeAsync(100)

expect(processed).toEqual([false, true, false])
expect(asyncQueuer.store.state.successCount).toBe(3)
})

})
})