Interface: RetryOptions

Options for retry.

Extends

Properties

backoff?

optional backoff?: RetryBackoff

How the delay grows per attempt:

  • fixed: delay every time
  • linear: delay * attempt
  • exponential: delay * 2^(attempt - 1)

Default Value

'exponential'

delay?

optional delay?: number

Base delay between attempts in milliseconds.

Default Value

1000

jitter?

optional jitter?: boolean

Adds randomness (delay * (0.5 ~ 1)) to avoid thundering-herd retries. Disable for deterministic timing (e.g. in tests).

Default Value

true

maxDelay?

optional maxDelay?: number

Upper bound for the computed delay, in milliseconds.

Default Value

30000

onRetry?

optional onRetry?: (error, attempt, nextDelay) => void

Called before each retry — a good place for logging.

Parameters

error

unknown

The error thrown by the failed attempt.

attempt

number

The attempt number that just failed (1-based).

nextDelay

number

The delay before the next attempt, in milliseconds.

Returns

void


retries?

optional retries?: number

Number of retries after the first attempt fails.

Default Value

3

shouldRetry?

optional shouldRetry?: (error, attempt) => boolean

Decides whether a failure is worth retrying. Return false to rethrow immediately — e.g. business errors like 4xx usually should not be retried, while network errors and 5xx should.

Parameters

error

unknown

The error thrown by the failed attempt.

attempt

number

The attempt number that just failed (1-based).

Returns

boolean


signal?

optional signal?: AbortSignal

Cancels the operation. While waiting between attempts or polls the cancellation is observed immediately; an in-flight attempt is not interrupted (abort the underlying work yourself if needed).

Inherited from

AsyncControlOptions.signal