pub struct Backoff { /* private fields */ }Expand description
Exponential backoff with optional jitter and deadline.
Tracks current delay, retry count, and optional wall-clock deadline.
Call .wait(err).await to check exhaustion, sleep if retries remain,
and advance state. Returns Err(Exhausted(err)) when done.
Implementations§
Source§impl Backoff
impl Backoff
Sourcepub fn builder() -> BackoffBuilder
pub fn builder() -> BackoffBuilder
Create a builder.
Sourcepub async fn wait<E>(&mut self, err: E) -> Result<(), Exhausted<E>>
pub async fn wait<E>(&mut self, err: E) -> Result<(), Exhausted<E>>
Check exhaustion, sleep for the current delay, then advance.
Returns Ok(()) if retries remain (caller should loop).
Returns Err(Exhausted(err)) if max retries or deadline
reached — the caller should escalate or fail over.
If a deadline is set, the sleep is capped to not exceed it.
§Panics
Panics if called outside Runtime::block_on.
Sourcepub fn advance(&mut self)
pub fn advance(&mut self)
Advance the backoff state without sleeping.
Useful when the caller manages timing externally.
Sourcepub fn is_exhausted(&self) -> bool
pub fn is_exhausted(&self) -> bool
Whether retries are exhausted (max retries or deadline).
Returns false if neither limit is set.
Sourcepub fn current_delay(&self) -> Duration
pub fn current_delay(&self) -> Duration
The next delay (before jitter).