Skip to content

fix: correct maybeExecuteCount increment and add test for AbortSignal…#187

Open
MrPorky wants to merge 2 commits intoTanStack:mainfrom
MrPorky:fix-debouncer-abort-signal-count
Open

fix: correct maybeExecuteCount increment and add test for AbortSignal…#187
MrPorky wants to merge 2 commits intoTanStack:mainfrom
MrPorky:fix-debouncer-abort-signal-count

Conversation

@MrPorky
Copy link
Copy Markdown

@MrPorky MrPorky commented Mar 30, 2026

🎯 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.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 30, 2026

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 b053c44 and 3e3b7e1.

📒 Files selected for processing (1)
  • packages/pacer/tests/async-debouncer.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/pacer/tests/async-debouncer.test.ts

📝 Walkthrough

Walkthrough

Fixes an execution ID mismatch in AsyncDebouncer that caused getAbortSignal() to return null; the debouncer now keys retryers using the maybeExecuteCount captured at call time. A test was added to verify abort signal propagation and behavior.

Changes

Cohort / File(s) Summary
Release Documentation
.changeset/humble-coats-shop.md
Updates Changeset for a patch release of @tanstack/pacer, documenting the AsyncDebouncer abort-signal fix.
AsyncDebouncer Implementation
packages/pacer/src/async-debouncer.ts
Stop incrementing currentMaybeExecuteCount inside #execute; use the existing maybeExecuteCount for retryer keying so abort-signal retrieval aligns with the call-time count.
Test Suite Updates
packages/pacer/tests/async-debouncer.test.ts
Adds a test ensuring getAbortSignal() returns a live AbortSignal inside the debounced callback and becomes aborted when debouncer.abort() is invoked; minor import formatting change.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hopped through counts and tangled threads,
Found the missing id beneath my beds,
Now signals wake and signal true,
No more nulls to puzzle you—
Hooray, the debouncer's fixed its meds!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main changes: fixing a maybeExecuteCount increment issue and adding a test for AbortSignal functionality, which directly addresses the core problem reported.
Description check ✅ Passed The PR description follows the template with all required sections completed: the Changes section explains the fix, both checklist items are marked complete, and the Release Impact indicates a changeset was generated.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 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 e71ead1 and b053c44.

📒 Files selected for processing (3)
  • .changeset/humble-coats-shop.md
  • packages/pacer/src/async-debouncer.ts
  • packages/pacer/tests/async-debouncer.test.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant