[][src]Struct stubborn_io::ReconnectOptions

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>,
}

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

Methods

impl ReconnectOptions[src]

pub fn new() -> Self[src]

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.

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>, 
[src]

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),
    ]
});

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

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

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

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

Auto Trait Implementations

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

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