Reference / queue
backoff()
Returns how long, in milliseconds, to wait before retrying attempt n.
The wait doubles from BASE_DELAY_MS and stops at CEILING_MS;
jitter stops many workers retrying at the same moment.
function backoff(attempt: number, jitter?: number): number
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
attempt | number | — | Zero-based attempt index. |
jitter | number | Math.random() | In [0, 1). Zero gives the lower bound. |
Returns
A number in milliseconds: between half the window and the full window, never above 60_000.
Note A 429 or 503 carrying Retry-After overrides the computed delay. See Delivery semantics.
backoff(0, 0); // 125 backoff(3, 0); // 1_000 backoff(20, 1); // 60_000, capped