Exponential backoff for retrying something that failed: how long to wait before the next attempt, and whether a failure is still waiting that long. Pure: callers pass their own clock in, so the same failure state works on any thread and in a test.
- Source
Methods
(static) afterFailure(previous, nowMs) → {object}
The failure state after one more failure.
Parameters:
| Name | Type | Description |
|---|---|---|
previous | dynamic | the state afterFailure returned for the last failure, or invalid for the first |
nowMs | integer | the caller's clock, in milliseconds |
- Source
Returns:
an AA with attempts and retryAt, the time the next attempt may start on the same clock
- Type:
- object
(static) isWaiting(failure, nowMs) → {boolean}
Whether failure is still waiting out its delay at nowMs. False for invalid: nothing failed.
Parameters:
| Name | Type | Description |
|---|---|---|
failure | dynamic | |
nowMs | integer |
- Source
Returns:
- Type:
- boolean
(static) nextDelayMs(attempt) → {integer}
The delay before the retry that follows a 0-based attempt: 1 s, 2 s, 4 s, 8 s, 16 s, then capped at 30 s.
Parameters:
| Name | Type | Description |
|---|---|---|
attempt | integer |
- Source
Returns:
- Type:
- integer