fix(pacer): lastResult should reflect resolved value#196
fix(pacer): lastResult should reflect resolved value#196gwansikk wants to merge 5 commits intoTanStack:mainfrom
lastResult should reflect resolved value#196Conversation
📝 WalkthroughWalkthroughUpdates the Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
lastResult should reflect resolved value
lastResult should reflect resolved valuelastResult should reflect resolved value
There was a problem hiding this comment.
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
📒 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
🎯 Changes
lastResultinAsyncDebouncerState,AsyncThrottlerState, andAsyncRateLimiterStateis typed asReturnType<TFn> | undefined, which resolves toPromise<T> | undefinedsinceTFnextendsAnyAsyncFunction. At runtime, the stored value is always the awaited result.✅ Checklist
pnpm run test:pr.🚀 Release Impact
Summary by CodeRabbit
lastResultproperty to store the actual resolved value from async function executions instead of promise types.