BackoffPolicy
Defined in: src/pattern/BackoffPolicy.ts:22
Pure backoff-policy primitives — stateless functions of (restartCount)
to a delay in milliseconds. Decoupled from BackoffSupervisor
so callers can plug in their own policy without subclassing the
supervisor, and so the policy itself is trivially unit-testable.
Two built-ins:
-
exponentialBackoff—min × 2^nclamped tomax, with optional ± jitter expressed as a fraction of the un-jittered delay. This is the policy you usually want — fast-then-slow, randomised so a herd of clients doesn’t synchronise their reconnect attempts. -
linearBackoff—min + step × nclamped tomax. Niche; use when you specifically want bounded growth (e.g. polling cadence that should plateau quickly).
The randomness source defaults to Math.random but can be overridden
— pass a seeded RNG to make the policy deterministic in tests.
Methods
Section titled “Methods”delayFor()
Section titled “delayFor()”delayFor(
restartCount):number
Defined in: src/pattern/BackoffPolicy.ts:28
Delay in milliseconds before the next restart attempt. restartCount
is 0-based: the first restart (after the very first failure)
passes 0, the second restart passes 1, etc.
Parameters
Section titled “Parameters”restartCount
Section titled “restartCount”number
Returns
Section titled “Returns”number