콘텐츠로 이동
한국어

RetryOptions

이 콘텐츠는 아직 번역되지 않았습니다.

RetryOptions = object

Defined in: src/pattern/Retry.ts:1

readonly attempts: number

Defined in: src/pattern/Retry.ts:3

Total attempts including the initial call. Must be >= 1.


readonly optional delayMs?: number

Defined in: src/pattern/Retry.ts:5

Base delay between retries, in ms.


readonly optional factor?: number

Defined in: src/pattern/Retry.ts:7

Exponential-backoff multiplier applied to delayMs (default 1 — no backoff).


readonly optional maxDelayMs?: 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.


readonly optional onAttempt?: (err, attempt) => void

Defined in: src/pattern/Retry.ts:35

Called after each failed attempt; useful for logging/metrics.

Error

number

void


readonly optional random?: () => number

Defined in: src/pattern/Retry.ts:28

Override Math.random for deterministic tests.

number


readonly optional randomFactor?: 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.


readonly optional shouldRetry?: (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”.

Error

number

boolean


readonly optional sleep?: (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.

number

Promise<void>