pub struct ExponentialBackoff { /* private fields */ }
Implementations§
Source§impl ExponentialBackoff
An exponential backoff mechanism with optional jitter and immediate-first behavior.
impl ExponentialBackoff
An exponential backoff mechanism with optional jitter and immediate-first behavior.
This struct computes successive delays for reconnect attempts.
It starts from an initial delay and multiplies it by a factor on each iteration,
capping the delay at a maximum value. Random jitter is added (up to a configured
maximum) to the delay. When immediate_first
is true, the first call to next_duration
returns zero delay, triggering an immediate reconnect, after which the immediate flag is disabled.
Sourcepub const fn new(
delay_initial: Duration,
delay_max: Duration,
factor: f64,
jitter_ms: u64,
immediate_first: bool,
) -> Self
pub const fn new( delay_initial: Duration, delay_max: Duration, factor: f64, jitter_ms: u64, immediate_first: bool, ) -> Self
Creates a new [ExponentialBackoff]
instance.
Sourcepub fn next_duration(&mut self) -> Duration
pub fn next_duration(&mut self) -> Duration
Return the next backoff delay with jitter and update the internal state.
If the immediate_first
flag is set and this is the first call (i.e. the current
delay equals the initial delay), it returns Duration::ZERO
to trigger an immediate
reconnect and disables the immediate behavior for subsequent calls.
Sourcepub const fn current_delay(&self) -> Duration
pub const fn current_delay(&self) -> Duration
Returns the current base delay without jitter.
This represents the delay that would be used as the base for the next call to next()
,
before any jitter is applied.
Trait Implementations§
Source§impl Clone for ExponentialBackoff
impl Clone for ExponentialBackoff
Source§fn clone(&self) -> ExponentialBackoff
fn clone(&self) -> ExponentialBackoff
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more