Skip to content

feat: add retry function and @retry decorator #73

Description

@tabkram

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

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions