pub struct Backoff { /* private fields */ }Expand description
Truncated-exponential backoff with deterministic jitter.
Implementations§
Source§impl Backoff
impl Backoff
Sourcepub fn new(
initial: Duration,
max: Duration,
mandatory_stop: Duration,
seed: u64,
) -> Backoff
pub fn new( initial: Duration, max: Duration, mandatory_stop: Duration, seed: u64, ) -> Backoff
Construct a new backoff with explicit parameters.
seed controls jitter; pass 0 for the default seed.
Sourcepub fn install_buggify(&mut self, buggify: Buggify)
pub fn install_buggify(&mut self, buggify: Buggify)
Install a crate::Buggify helper on this schedule. The
retry_clock.skew label fires inside Self::next when
armed, multiplying the returned Duration by a seed-driven
factor in [0.5, 2.0]. Engines call this once after
constructing the Backoff; the moonpool engine threads the same
helper instance the crate::Connection is using so the four
labels share a single fire-counter map. ADR-0048.
Sourcepub fn next(&mut self) -> Duration
pub fn next(&mut self) -> Duration
Compute the next backoff delay.
On the very first call after construction (or after Self::reset), this returns the
initial delay. Subsequent calls double the previous delay, clamped at max, with a
jitter factor in [0%, 20%] of the next delay subtracted.
If the cumulative elapsed delay exceeds mandatory_stop, the next delay snaps to max
and the cumulative counter resets to zero. This mirrors Java’s behaviour
(Backoff.java:60-89).