pub struct ReconnectState { /* private fields */ }Expand description
Reconnection state tracker for managing connection attempts and backoff.
This helper tracks the number of reconnection attempts and calculates the appropriate backoff delay using exponential backoff.
§Example
use monocoque_core::reconnect::ReconnectState;
use monocoque_core::options::SocketOptions;
use std::time::Duration;
let options = SocketOptions::default()
.with_reconnect_ivl(Duration::from_millis(100))
.with_reconnect_ivl_max(Duration::from_secs(10));
let mut reconnect = ReconnectState::new(&options);
// First attempt uses base interval
assert_eq!(reconnect.next_delay(), Duration::from_millis(100));
// Subsequent attempts use exponential backoff
assert_eq!(reconnect.next_delay(), Duration::from_millis(200));
assert_eq!(reconnect.next_delay(), Duration::from_millis(400));
// Reset on successful connection
reconnect.reset();
assert_eq!(reconnect.next_delay(), Duration::from_millis(100));Implementations§
Source§impl ReconnectState
impl ReconnectState
Sourcepub const fn new(options: &SocketOptions) -> ReconnectState
pub const fn new(options: &SocketOptions) -> ReconnectState
Create a new reconnection state tracker from socket options.
Sourcepub fn next_delay(&mut self) -> Duration
pub fn next_delay(&mut self) -> Duration
Get the delay for the next reconnection attempt.
This calculates the exponential backoff delay based on the number
of previous attempts. The delay doubles with each attempt until
it reaches reconnect_ivl_max.
§Returns
The duration to wait before the next reconnection attempt.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset the reconnection state after a successful connection.
This resets the attempt counter and interval back to the base values.
Sourcepub const fn base_interval(&self) -> Duration
pub const fn base_interval(&self) -> Duration
Get the base reconnection interval.
Sourcepub const fn max_interval(&self) -> Duration
pub const fn max_interval(&self) -> Duration
Get the maximum reconnection interval.
Sourcepub const fn current_interval(&self) -> Duration
pub const fn current_interval(&self) -> Duration
Get the current reconnection interval.
Trait Implementations§
Source§impl Clone for ReconnectState
impl Clone for ReconnectState
Source§fn clone(&self) -> ReconnectState
fn clone(&self) -> ReconnectState
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ReconnectState
impl RefUnwindSafe for ReconnectState
impl Send for ReconnectState
impl Sync for ReconnectState
impl Unpin for ReconnectState
impl UnsafeUnpin for ReconnectState
impl UnwindSafe for ReconnectState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more