fix(async-queuer): use nullish check in #tick to handle falsy queue items #201
Closedsimonmeyerrr(GitHub profile, opens in a new tab)wants to merge 3 commits into
main fromrefs/pull/201/headopened - packages/pacer/src/async-queuer.ts lines 439 to 443Resolvedby simonmeyerrr(GitHub profile, opens in a new tab)@@ -437,7 +437,7 @@437437 this.store.state.items.length > 0438438 ) {439439 const nextItem = this.peekNextItem()440- if (!nextItem) {440+ if (nextItem === undefined) {441441 break442442 }443443 activeItems.push(nextItem)packages/pacer/tests/async-queuer.test.ts line 1162Resolvedby simonmeyerrr(GitHub profile, opens in a new tab)@@ -1097,0 +1142,21 @@1142+ it('should process items with value false', async () => {1143+ const processed: Array<boolean> = []1144+ const asyncQueuer = new AsyncQueuer<boolean>(1145+ async (item) => {1146+ processed.push(item)1147+ return item1148+ },1149+ { started: false },1150+ )1151+1152+ asyncQueuer.addItem(false)1153+ asyncQueuer.addItem(true)1154+ asyncQueuer.addItem(false)1155+ asyncQueuer.start()1156+1157+ await vi.advanceTimersByTimeAsync(100)1158+1159+ expect(processed).toEqual([false, true, false])1160+ expect(asyncQueuer.store.state.successCount).toBe(3)1161+ })1162+
KevinVandy closed this
Sign in to join this conversation.
📝 Walkthrough
Walkthrough#
This pull request fixes
AsyncQueuer#tickto properly handle falsy item values. The loop break condition was changed from a generic falsy check to an explicitundefinedcheck, allowing items with values like0,false, and''to proceed through processing instead of being silently excluded.Changes#
packages/pacer/src/async-queuer.ts,packages/pacer/tests/async-queuer.test.tsundefinedinstead of falsy values, and added comprehensive test suite with three cases validating correct handling of0,'', andfalseitems during queue processing..changeset/young-planes-clap.md@tanstack/paceraddressing falsy item exclusion inAsyncQueuer#tick.Estimated code review effort#
🎯 2 (Simple) | ⏱️ ~10 minutes
Poem#
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share