Skip to content

fix(pacer): lastResult should reflect resolved value#196

Open
gwansikk wants to merge 5 commits intoTanStack:mainfrom
gwansikk:main
Open

fix(pacer): lastResult should reflect resolved value#196
gwansikk wants to merge 5 commits intoTanStack:mainfrom
gwansikk:main

Conversation

@gwansikk
Copy link
Copy Markdown

@gwansikk gwansikk commented Apr 14, 2026

🎯 Changes

lastResult in AsyncDebouncerState, AsyncThrottlerState, and AsyncRateLimiterState is typed as ReturnType<TFn> | undefined, which resolves to Promise<T> | undefined since TFn extends AnyAsyncFunction. At runtime, the stored value is always the awaited result.

- lastResult: ReturnType<TFn> | undefined
+ lastResult: Awaited<ReturnType<TFn>> | undefined

✅ 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
    • Corrected async utilities' lastResult property to store the actual resolved value from async function executions instead of promise types.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 14, 2026

📝 Walkthrough

Walkthrough

Updates the lastResult type across three async utility classes in the @tanstack/pacer package to store the resolved value (Awaited<ReturnType<TFn>>) instead of the raw return type, with a corresponding changeset entry documenting the patch-level bump.

Changes

Cohort / File(s) Summary
Type Definition Clarification
packages/pacer/src/async-debouncer.ts, packages/pacer/src/async-rate-limiter.ts, packages/pacer/src/async-throttler.ts
Updated lastResult property type from ReturnType<TFn> | undefined to Awaited<ReturnType<TFn>> | undefined across all three async state interfaces to correctly represent resolved values.
Changelog Entry
.changeset/pretty-llamas-happen.md
Added changeset documenting patch-level bump for @tanstack/pacer with note that lastResult reflects the resolved value.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

A rabbit hops through types with glee, 🐰
Awaited values, now they're free!
No promises stored, just truth revealed,
The resolved results are now sealed.
Three utilities in harmony!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change—correcting the type of lastResult to reflect the resolved value rather than the raw Promise type.
Description check ✅ Passed The PR description covers all required sections: detailed explanation of changes with code diff, completed checklist items confirming contribution guide compliance and testing, and clear release impact statement with changeset added.
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

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

@gwansikk gwansikk changed the title fix(types): lastResult should reflect resolved value fix: lastResult should reflect resolved value Apr 14, 2026
@gwansikk gwansikk changed the title fix: lastResult should reflect resolved value fix(pacer): lastResult should reflect resolved value Apr 18, 2026
@gwansikk gwansikk marked this pull request as ready for review April 18, 2026 06:49
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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/pacer/src/async-throttler.ts (1)

121-125: 🛠️ Refactor suggestion | 🟠 Major

Consider updating onSuccess callback type for consistency.

The onSuccess callback receives the awaited result at runtime (line 427), but its type signature still declares result: ReturnType<TFn>, which resolves to Promise<T>. This creates a type inconsistency that's currently hidden by the as ReturnType<TFn> cast at line 427.

For type correctness and consistency with the lastResult fix, consider updating the callback signature:

  onSuccess?: (
-   result: ReturnType<TFn>,
+   result: Awaited<ReturnType<TFn>>,
    args: Parameters<TFn>,
    asyncThrottler: AsyncThrottler<TFn>,
  ) => void

This same pattern appears in async-debouncer.ts and async-rate-limiter.ts.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/pacer/src/async-throttler.ts` around lines 121 - 125, Update the
onSuccess callback type to accept the awaited result instead of the raw Promise
so the runtime value matches the type: change the signature of onSuccess on
AsyncThrottler<TFn> to use Awaited<ReturnType<TFn>> (or equivalent) for the
result parameter and adjust any related references like lastResult; apply the
same change pattern to the onSuccess definitions in async-debouncer.ts and
async-rate-limiter.ts to keep types consistent with the actual awaited value
passed at runtime (look for the onSuccess property and places where result is
cast as ReturnType<TFn>).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@packages/pacer/src/async-throttler.ts`:
- Around line 121-125: Update the onSuccess callback type to accept the awaited
result instead of the raw Promise so the runtime value matches the type: change
the signature of onSuccess on AsyncThrottler<TFn> to use
Awaited<ReturnType<TFn>> (or equivalent) for the result parameter and adjust any
related references like lastResult; apply the same change pattern to the
onSuccess definitions in async-debouncer.ts and async-rate-limiter.ts to keep
types consistent with the actual awaited value passed at runtime (look for the
onSuccess property and places where result is cast as ReturnType<TFn>).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4aa19ba5-9e8a-412f-850e-c321ae804e4b

📥 Commits

Reviewing files that changed from the base of the PR and between 05b7c4d and e8d0bcd.

📒 Files selected for processing (4)
  • .changeset/pretty-llamas-happen.md
  • packages/pacer/src/async-debouncer.ts
  • packages/pacer/src/async-rate-limiter.ts
  • packages/pacer/src/async-throttler.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