Goal
Add a retry() function and @retry() method decorator for transient failures.
const getInvoice = retry(
async (invoiceId: string) => billingApi.getInvoice(invoiceId),
{
attempts: 3,
backoff: 'exponential',
initialDelay: 200,
maxDelay: 2_000,
jitter: true,
shouldRetry: (error) => error.status >= 500
}
);
Scope
- Configurable maximum attempts
- Fixed, exponential, and custom backoff
- Optional jitter and maximum delay
shouldRetry(error, attempt) predicate
onRetry hook and AbortSignal support
- Preserve the final error and stack
- Unit tests and documentation
Trace integration
Model each attempt as a child node and record delay, failure reason, and final outcome.
Acceptance criteria
- Sync and async functions are supported
- Non-retryable errors stop immediately
- Cancellation stops pending delays and rejects predictably
- Public API is exported from the package entry point
Goal
Add a
retry()function and@retry()method decorator for transient failures.Scope
shouldRetry(error, attempt)predicateonRetryhook andAbortSignalsupportTrace integration
Model each attempt as a child node and record delay, failure reason, and final outcome.
Acceptance criteria