RetryOptions
此内容尚不支持你的语言。
RetryOptions =
object
Defined in: src/pattern/Retry.ts:30
Properties
Section titled “Properties”attempts
Section titled “attempts”
readonlyattempts:number
Defined in: src/pattern/Retry.ts:32
Total attempts including the initial call. Must be >= 1.
delayMs?
Section titled “delayMs?”
readonlyoptionaldelayMs?:number
Defined in: src/pattern/Retry.ts:34
Base delay between retries, in ms.
factor?
Section titled “factor?”
readonlyoptionalfactor?:number
Defined in: src/pattern/Retry.ts:36
Exponential-backoff multiplier applied to delayMs (default 1 — no backoff).
maxDelayMs?
Section titled “maxDelayMs?”
readonlyoptionalmaxDelayMs?:number
Defined in: src/pattern/Retry.ts:44
Upper bound for any individual retry delay. Defaults to
DEFAULT_MAX_RETRY_DELAY_MS (60 000 ms) — pass
Number.POSITIVE_INFINITY for the unbounded schedule this option used
to have by default, in which case the hard clamp at the 32-bit timer
limit (2_147_483_647 ms, ~24.9 days) is the only ceiling left.
onAttempt?
Section titled “onAttempt?”
readonlyoptionalonAttempt?: (err,attempt) =>void
Defined in: src/pattern/Retry.ts:65
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:58
Override Math.random for deterministic tests.
Returns
Section titled “Returns”number
randomFactor?
Section titled “randomFactor?”
readonlyoptionalrandomFactor?:number
Defined in: src/pattern/Retry.ts:56
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.
scheduler?
Section titled “scheduler?”
readonlyoptionalscheduler?:Scheduler
Defined in: src/pattern/Retry.ts:86
Where the delay between attempts is armed. Default: a host timer.
The same thing sleep buys, without the caller writing the adapter:
scheduler: system.scheduler puts the whole backoff schedule on virtual
time under a ManualScheduler, so a five-attempt exponential backoff is
exact and instant instead of being the sum of five real delays (#1424).
sleep wins if both are given — it is the lower-level door, and a caller
that supplied one meant it.
shouldRetry?
Section titled “shouldRetry?”
readonlyoptionalshouldRetry?: (err,attempt) =>boolean
Defined in: src/pattern/Retry.ts:63
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:74
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>
