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
impl ReconnectOptions
Sourcepub fn new() -> Self
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.
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
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),
]
});