pub struct ReconnectManager { /* private fields */ }Expand description
Manages automatic reconnection with exponential backoff and jitter.
Implementations§
Source§impl ReconnectManager
impl ReconnectManager
Sourcepub fn new(config: ReconnectConfig) -> Self
pub fn new(config: ReconnectConfig) -> Self
Create a new reconnect manager.
Sourcepub fn on_disconnect(&mut self)
pub fn on_disconnect(&mut self)
Call when the connection drops.
Starts the backoff timer and transitions to WaitingBackoff.
Sourcepub fn on_connect(&mut self)
pub fn on_connect(&mut self)
Call when a reconnect attempt succeeds.
Resets backoff if connection was stable, or keeps reduced backoff if we reconnected quickly.
Sourcepub fn on_failure(&mut self)
pub fn on_failure(&mut self)
Call when a reconnect attempt fails.
Increases backoff interval exponentially with jitter.
Sourcepub fn on_attempt_start(&mut self)
pub fn on_attempt_start(&mut self)
Call when a reconnect attempt is starting.
Sourcepub fn should_reconnect(&mut self) -> bool
pub fn should_reconnect(&mut self) -> bool
Returns true if it’s time to attempt a reconnect right now.
Call this periodically in your main loop.
Sourcepub fn time_until_reconnect(&self) -> Duration
pub fn time_until_reconnect(&self) -> Duration
Returns how long until the next reconnect attempt.
Returns Duration::ZERO if ready now.
Sourcepub fn check_stability(&mut self)
pub fn check_stability(&mut self)
Check if the current connection has been stable long enough to fully reset the backoff counter.
Call periodically while connected.
Sourcepub fn state(&self) -> &ReconnectState
pub fn state(&self) -> &ReconnectState
Returns the current reconnect state.
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Returns true if the connection is currently up.
Sourcepub fn is_giving_up(&self) -> bool
pub fn is_giving_up(&self) -> bool
Returns true if we have given up reconnecting.
Sourcepub fn attempts(&self) -> u32
pub fn attempts(&self) -> u32
Returns the number of failed attempts since last successful connect.
Sourcepub fn total_reconnects(&self) -> u64
pub fn total_reconnects(&self) -> u64
Returns total successful reconnects.
Sourcepub fn current_interval(&self) -> Duration
pub fn current_interval(&self) -> Duration
Returns the current backoff interval.
Sourcepub fn total_downtime(&self) -> Duration
pub fn total_downtime(&self) -> Duration
Returns total accumulated downtime.
Sourcepub fn config(&self) -> &ReconnectConfig
pub fn config(&self) -> &ReconnectConfig
Returns a reference to the config.