std/backoff
On this page
Index
- type
Backoff- method
Backoff.delay
- method
- fn
retry - fn
retry_notify - fn
always
Types
Backoff
struct Backoff {
initial: Duration = 500ms
multiplier: Float = 1.5
randomization: Float = 0.5
max_interval: Duration = 60s
max_elapsed: Duration = 15m
max_tries: Int = 0
}The schedule (cenkalti/backoff v4’s defaults): the first delay is
initial, each next one multiplier times the last up to
max_interval, each randomized within randomization of itself.
Backoff.delay
fn (b: Backoff) delay(attempt: Int, rand: Rand) -> Duration uses randThe delay before retry number attempt (0 for the first retry):
initial times multiplier attempt times, capped at max_interval,
randomized with one rand.float().
Functions
retry
fn retry[T, E, fx: Effects](b: Backoff, clock: Clock, rand: Rand, op: fn() -> T ! E uses fx, retryable: fn(E) -> Bool) -> T ! E uses (clock, rand, fx)Calls op until it succeeds, retryable(e) is false, or a limit of b
runs out, and then answers op’s last result; sleeps on clock between
tries (a cancellation point: a cancelled task unwinds there).
retry_notify
fn retry_notify[T, E, fx: Effects, rx: Effects, nx: Effects](b: Backoff, clock: Clock, rand: Rand, op: fn() -> T ! E uses fx, retryable: fn(E) -> Bool uses rx, notify: fn(E, Duration) -> () uses nx) -> T ! E uses (clock, rand, fx, rx, nx)retry, calling notify(e, d) with each error before sleeping d (cenkalti/backoff v4’s RetryNotify): to log or count the retries. retryable and notify may have effects of their own (each its own effect variable: op’s need not include a log’s).
always
fn always[E]() -> fn(E) -> BoolA retryable that retries every error.
↑ index