RetryOptions
Este conteúdo não está disponível em sua língua ainda.
RetryOptions =
object
Defined in: src/pattern/Retry.ts:1
Properties
Section titled “Properties”attempts
Section titled “attempts”
readonlyattempts:number
Defined in: src/pattern/Retry.ts:3
Total attempts including the initial call. Must be >= 1.
delayMs?
Section titled “delayMs?”
readonlyoptionaldelayMs?:number
Defined in: src/pattern/Retry.ts:5
Base delay between retries, in ms.
factor?
Section titled “factor?”
readonlyoptionalfactor?:number
Defined in: src/pattern/Retry.ts:7
Exponential-backoff multiplier applied to delayMs (default 1 — no backoff).
maxDelayMs?
Section titled “maxDelayMs?”
readonlyoptionalmaxDelayMs?:number
Defined in: src/pattern/Retry.ts:14
Upper bound for any individual retry delay. Unbounded by default; the
hard clamp at the 32-bit timer limit (2_147_483_647 ms, ~24.9 days)
still applies, so an omitted cap degrades to a very long wait rather
than to no wait at all.
onAttempt?
Section titled “onAttempt?”
readonlyoptionalonAttempt?: (err,attempt) =>void
Defined in: src/pattern/Retry.ts:35
Called after each failed attempt; useful for logging/metrics.
Parameters
Section titled “Parameters”Error
attempt
Section titled “attempt”number
Returns
Section titled “Returns”void
random?
Section titled “random?”
readonlyoptionalrandom?: () =>number
Defined in: src/pattern/Retry.ts:28
Override Math.random for deterministic tests.
Returns
Section titled “Returns”number
randomFactor?
Section titled “randomFactor?”
readonlyoptionalrandomFactor?:number
Defined in: src/pattern/Retry.ts:26
Jitter fraction in [0, 1]. The delay is multiplied by
1 + random(-randomFactor, +randomFactor), so N callers that failed on
the same upstream event stop retrying in lockstep and hammering the
recovering dependency in synchronised waves.
Default 0 — unlike exponentialBackoff, whose callers are always
fleets of reconnecting clients, retry wraps a single call and its
schedule has always been deterministic. Opting in is the change; 0.2
is the spread the rest of the project uses.
shouldRetry?
Section titled “shouldRetry?”
readonlyoptionalshouldRetry?: (err,attempt) =>boolean
Defined in: src/pattern/Retry.ts:33
Predicate that decides whether a specific error is retryable. Return false to short-circuit with the final error. Defaults to “retry any”.
Parameters
Section titled “Parameters”Error
attempt
Section titled “attempt”number
Returns
Section titled “Returns”boolean
sleep?
Section titled “sleep?”
readonlyoptionalsleep?: (ms) =>Promise<void>
Defined in: src/pattern/Retry.ts:44
How the delay between attempts is awaited. Defaults to setTimeout.
Override to take the retry loop off the wall clock — a
ManualScheduler-backed sleep makes the backoff schedule exact and
instant in tests, where a real timer’s ±quantum jitter makes a capped
delay indistinguishable from an uncapped one. Same escape hatch as
random above, for the other half of the schedule.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”Promise<void>
