Skip to content
Source
Sign inSign up
TanStack/pacer

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

Opengwansikk(GitHub profile, opens in a new tab)wants to merge 6 commits intomain fromrefs/pull/196/headopened

🎯 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.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      📝 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 nameStatusExplanation
      Title check✅ PassedThe 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✅ PassedThe 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✅ PassedNo 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.
    2. gwansikk(GitHub profile, opens in a new tab) changed the title

    3. gwansikk(GitHub profile, opens in a new tab) changed the title

    4. 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 05b7c4d905fc601afb77353a3df6533d734cd896 and e8d0bcd4b4cf1dda8c647ddead62a27e318a4e7b.

      📒 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 in to join this conversation.