fix(pacer): `lastResult` should reflect resolved value #196
main fromrefs/pull/196/head·opened 🎯 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'
lastResultproperty to store the actual resolved value from async function executions instead of promise types.
- Corrected async utilities'
- 1
gwansikk(GitHub profile, opens in a new tab) changed the title
gwansikk(GitHub profile, opens in a new tab) changed the title
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 | 🟠 MajorConsider updating
onSuccesscallback type for consistency.The
onSuccesscallback receives the awaited result at runtime (line 427), but its type signature still declaresresult: ReturnType<TFn>, which resolves toPromise<T>. This creates a type inconsistency that's currently hidden by theas ReturnType<TFn>cast at line 427.For type correctness and consistency with the
lastResultfix, consider updating the callback signature:onSuccess?: ( - result: ReturnType<TFn>, + result: Awaited<ReturnType<TFn>>, args: Parameters<TFn>, asyncThrottler: AsyncThrottler<TFn>, ) => voidThis same pattern appears in
async-debouncer.tsandasync-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.mdpackages/pacer/src/async-debouncer.tspackages/pacer/src/async-rate-limiter.tspackages/pacer/src/async-throttler.ts
Sign in to join this conversation.
📝 Walkthrough
Walkthrough#
Updates the
lastResulttype across three async utility classes in the@tanstack/pacerpackage 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#
packages/pacer/src/async-debouncer.ts,packages/pacer/src/async-rate-limiter.ts,packages/pacer/src/async-throttler.tslastResultproperty type fromReturnType<TFn> | undefinedtoAwaited<ReturnType<TFn>> | undefinedacross all three async state interfaces to correctly represent resolved values..changeset/pretty-llamas-happen.md@tanstack/pacerwith note thatlastResultreflects the resolved value.Estimated code review effort#
🎯 1 (Trivial) | ⏱️ ~3 minutes
Poem#
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
lastResultto reflect the resolved value rather than the raw Promise type.✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands and usage tips.