fix: correct maybeExecuteCount increment and add test for AbortSignal… #187
main fromrefs/pull/187/head·opened 🎯 Changes#
This PR fixes an issue in AsyncDebouncer where calling debouncer.getAbortSignal() incorrectly returns null, preventing consumers from properly attaching abort signals to underlying async operations.
✅ Checklist#
- I have followed the steps in the Contributing guide.
- I have tested this code locally with
pnpm run test:pr.
🚀 Release Impact#
- This change affects published code, and I have generated a changeset.
- This change is docs/CI/dev-only (no release).
Summary by CodeRabbit#
Bug Fixes
- Abort signals are now correctly propagated to underlying async tasks; signals are attached and become aborted as expected.
Tests
- Added test coverage validating abort-signal retrieval and abort behavior during debounced async operations.
- 1
🧹 Nitpick comments (1)
packages/pacer/tests/async-debouncer.test.ts (1)
1362-1377: Test name overstates behavior; cancellation is not asserted.This test currently verifies signal availability, not cancellation. Consider asserting abort semantics (
debouncer.abort()+signal.aborted/abort listener) to match the test intent.✅ Suggested test tightening
- it('should return an AbortSignal that can be used to cancel execution', async () => { + it('should return an AbortSignal and mark it aborted when abort() is called', async () => { const debouncer = new AsyncDebouncer( async () => { const signal = debouncer.getAbortSignal() expect(signal).toBeInstanceOf(AbortSignal) + expect(signal?.aborted).toBe(false) return 'result' }, { wait: 300 }, ) - debouncer.maybeExecute() + debouncer.maybeExecute() vi.advanceTimersByTime(150) const promise = debouncer.maybeExecute() vi.advanceTimersByTime(300) + debouncer.abort() + expect(debouncer.getAbortSignal()?.aborted ?? true).toBe(true) await promise })🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/pacer/tests/async-debouncer.test.ts` around lines 1362 - 1377, The test name claims cancellation behavior but only checks that getAbortSignal() returns an AbortSignal; update the test for AsyncDebouncer to actually assert abort semantics by invoking debouncer.abort() (or triggering cancellation via the API), then asserting the returned signal from debouncer.getAbortSignal() becomes aborted (signal.aborted true) and/or that an abort event listener is invoked; reference the AsyncDebouncer class and its methods maybeExecute, getAbortSignal, and abort to locate the change and add assertions that verify the signal was aborted after calling abort().🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed. Nitpick comments: In `@packages/pacer/tests/async-debouncer.test.ts`: - Around line 1362-1377: The test name claims cancellation behavior but only checks that getAbortSignal() returns an AbortSignal; update the test for AsyncDebouncer to actually assert abort semantics by invoking debouncer.abort() (or triggering cancellation via the API), then asserting the returned signal from debouncer.getAbortSignal() becomes aborted (signal.aborted true) and/or that an abort event listener is invoked; reference the AsyncDebouncer class and its methods maybeExecute, getAbortSignal, and abort to locate the change and add assertions that verify the signal was aborted after calling abort().
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID:
7ba60ee3-9931-4ff6-83e4-74ed1848e762📥 Commits
Reviewing files that changed from the base of the PR and between e71ead12970d5b8e777fe91f2e4a70fdb7f2fcd3 and b053c449c0c62766394a74ac91424754b94d7dce.
📒 Files selected for processing (3)
.changeset/humble-coats-shop.mdpackages/pacer/src/async-debouncer.tspackages/pacer/tests/async-debouncer.test.ts
Sign in to join this conversation.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID:
137b425c-a44d-4780-80e8-6d498c2ea647📥 Commits
Reviewing files that changed from the base of the PR and between b053c449c0c62766394a74ac91424754b94d7dce and 3e3b7e152f5412492be4fa91899b979ba61f537a.
📒 Files selected for processing (1)
packages/pacer/tests/async-debouncer.test.ts🚧 Files skipped from review as they are similar to previous changes (1)
📝 Walkthrough
Walkthrough#
Fixes an execution ID mismatch in
AsyncDebouncerthat causedgetAbortSignal()to returnnull; the debouncer now keys retryers using themaybeExecuteCountcaptured at call time. A test was added to verify abort signal propagation and behavior.Changes#
.changeset/humble-coats-shop.mdpatchrelease of@tanstack/pacer, documenting theAsyncDebouncerabort-signal fix.packages/pacer/src/async-debouncer.tscurrentMaybeExecuteCountinside#execute; use the existingmaybeExecuteCountfor retryer keying so abort-signal retrieval aligns with the call-time count.packages/pacer/tests/async-debouncer.test.tsgetAbortSignal()returns a liveAbortSignalinside the debounced callback and becomes aborted whendebouncer.abort()is invoked; minor import formatting change.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