pub struct ReconnectOptions(/* private fields */);
Expand description
User specified options that control the behavior of the ReconnectStream upon disconnect.
Implementations§
Source§impl ReconnectOptions
impl ReconnectOptions
Sourcepub fn new() -> Self
pub fn new() -> Self
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.
Sourcepub fn with_retries_generator<F, I, IN>(self, retries_generator: F) -> Self
pub fn with_retries_generator<F, I, IN>(self, retries_generator: F) -> Self
Represents a function that generates an Iterator to schedule the wait between reconnection attempts. This method allows the user to provide any function that returns a value which 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),
]
});
Sourcepub fn with_exit_if_first_connect_fails(self, value: bool) -> Self
pub fn with_exit_if_first_connect_fails(self, value: bool) -> Self
If this is set to true, if the initial connect method of the ReconnectStream item fails, then no further reconnects will be attempted
Sourcepub fn with_on_connect_callback(
self,
cb: impl Fn() + 'static + Send + Sync,
) -> Self
pub fn with_on_connect_callback( self, cb: impl Fn() + 'static + Send + Sync, ) -> Self
Invoked when the ReconnectStream establishes a connection
Sourcepub fn with_on_disconnect_callback(
self,
cb: impl Fn() + 'static + Send + Sync,
) -> Self
pub fn with_on_disconnect_callback( self, cb: impl Fn() + 'static + Send + Sync, ) -> Self
Invoked when the ReconnectStream loses its active connection
Sourcepub fn with_on_connect_fail_callback(
self,
cb: impl Fn() + 'static + Send + Sync,
) -> Self
pub fn with_on_connect_fail_callback( self, cb: impl Fn() + 'static + Send + Sync, ) -> Self
Invoked when the ReconnectStream fails a connection attempt
Trait Implementations§
Source§impl Clone for ReconnectOptions
impl Clone for ReconnectOptions
Source§fn clone(&self) -> ReconnectOptions
fn clone(&self) -> ReconnectOptions
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more