Skip to content

feat(async/unstable): add onRetry option to retry() - #7297

Open
tomas-zijdemans wants to merge 1 commit into
denoland:mainfrom
tomas-zijdemans:feat-async-retry-onretry
Open

feat(async/unstable): add onRetry option to retry()#7297
tomas-zijdemans wants to merge 1 commit into
denoland:mainfrom
tomas-zijdemans:feat-async-retry-onretry

Conversation

@tomas-zijdemans

@tomas-zijdemans tomas-zijdemans commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Adds an unstable onRetry callback to retry() so callers can log or measure retries without abusing isRetriable. Stable retry stays untouched.

Why

isRetriable(error) runs before the attempts-remaining check, so it also sees the terminal failure that becomes RetryError. It cannot tell whether another attempt will follow.

onRetry can. It fires after the retry decision is final, immediately before the backoff sleep.

API

onRetry?: (error: unknown, attempt: number, delay: number) => void;
  • attempt is the 1-based number of the failed attempt.
  • delay is the post-jitter delay passed to the sleep.
  • The callback is synchronous. Its return value is ignored, and a throw stops retrying.
  • It never fires for the terminal failure, an error rejected by isRetriable, or an already-aborted signal.

The callback observes a retry but cannot veto it or change its delay.

Review and testing

unstable_retry.ts follows the unstable-first pattern previously used for isRetriable and signal.

Ten tests cover arguments, timing, terminal failure, rejected errors, and abort behavior. deno task ok passes.

@github-actions github-actions Bot added the async label Aug 23, 2026
@codecov

codecov Bot commented Aug 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.00000% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.99%. Comparing base (ca58f94) to head (d9d328c).

Files with missing lines Patch % Lines
async/unstable_retry.ts 60.00% 18 Missing and 8 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7297      +/-   ##
==========================================
- Coverage   95.03%   94.99%   -0.05%     
==========================================
  Files         617      619       +2     
  Lines       51637    51957     +320     
  Branches     9359     9426      +67     
==========================================
+ Hits        49075    49355     +280     
- Misses       2021     2048      +27     
- Partials      541      554      +13     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant