Struct stream_reconnect::ReconnectOptions[][src]

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

User specified options that control the behavior of the ReconnectStream upon disconnect.

Fields

retries_to_attempt_fn: Arc<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 ReconnectStream item fails, then no further reconnects will be attempted

on_connect_callback: Arc<dyn Fn() + Send + Sync>

Invoked when the ReconnectStream establishes a connection

on_disconnect_callback: Arc<dyn Fn() + Send + Sync>

Invoked when the ReconnectStream loses its active connection

on_connect_fail_callback: Arc<dyn Fn() + Send + Sync>

Invoked when the ReconnectStream fails a connection attempt

Implementations

By default, the ReconnectStream 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.

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 stream_reconnect::ReconnectOptions;

// With the below vector, the ReconnectStream 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),
    ]
});

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.