Struct ReconnectOptions

Source
pub struct ReconnectOptions {
    pub retries_to_attempt_fn: Box<dyn Fn() -> DurationIterator + Send + Sync>,
    pub exit_if_first_connect_fails: bool,
    pub on_connect_callback: Box<dyn Fn() + Send + Sync>,
    pub on_disconnect_callback: Box<dyn Fn() + Send + Sync>,
    pub on_connect_fail_callback: Box<dyn Fn() + Send + Sync>,
}
Expand description

User specified options that control the behavior of the stubborn-io upon disconnect.

Fields§

§retries_to_attempt_fn: Box<dyn Fn() -> DurationIterator + Send + Sync>

Represents a function that generates an Iterator to schedule the wait between reconnection attempts.

§exit_if_first_connect_fails: bool

If this is set to true, if the initial connect method of the stubborn-io item fails, then no further reconnects will be attempted

§on_connect_callback: Box<dyn Fn() + Send + Sync>

Invoked when the StubbornIo establishes a connection

§on_disconnect_callback: Box<dyn Fn() + Send + Sync>

Invoked when the StubbornIo loses its active connection

§on_connect_fail_callback: Box<dyn Fn() + Send + Sync>

Invoked when the StubbornIo fails a connection attempt

Implementations§

Source§

impl ReconnectOptions

Source

pub fn new() -> Self

By default, the stubborn-io will not try to reconnect if the first connect attempt fails. By default, the retries iterator waits longer and longer between reconnection attempts, until it eventually perpetually tries to reconnect every 30 minutes.

Source

pub fn with_retries_generator<F, I, IN>(self, retries_generator: F) -> Self
where F: 'static + Send + Sync + Fn() -> IN, I: 'static + Send + Sync + Iterator<Item = Duration>, IN: IntoIterator<IntoIter = I, Item = Duration>,

This convenience function allows the user to provide any function that returns a value that is convertible into an iterator, such as an actual iterator or a Vec.

§Examples
use std::time::Duration;
use stubborn_io::ReconnectOptions;

// With the below vector, the stubborn-io item will try to reconnect three times,
// waiting 2 seconds between each attempt. Once all three tries are exhausted,
// it will stop attempting.
let options = ReconnectOptions::new().with_retries_generator(|| {
    vec![
        Duration::from_secs(2),
        Duration::from_secs(2),
        Duration::from_secs(2),
    ]
});
Source

pub fn with_exit_if_first_connect_fails(self, value: bool) -> Self

Source

pub fn with_on_connect_callback( self, cb: impl Fn() + 'static + Send + Sync, ) -> Self

Source

pub fn with_on_disconnect_callback( self, cb: impl Fn() + 'static + Send + Sync, ) -> Self

Source

pub fn with_on_connect_fail_callback( self, cb: impl Fn() + 'static + Send + Sync, ) -> Self

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V