pub struct Strategy { /* private fields */ }Expand description
Configurable retry strategy.
Implements Default, which returns an exponential backoff strategy
with a delay of 1 second and a maximum of 5 retries.
§Example
let strategy = Strategy::default()
.with_max_retries(3);
let future = strategy.retry(|| {
// do some real-world stuff here...
future::ok::<u32, ::std::io::Error>(42)
});Implementations§
Source§impl Strategy
impl Strategy
Sourcepub fn exponential(delay: Duration) -> Strategy
pub fn exponential(delay: Duration) -> Strategy
Creates a retry strategy driven by exponential back-off.
The specified duration will be multiplied by 2^n, where n is
the number of failed attempts.
Sourcepub fn fibonacci(delay: Duration) -> Strategy
pub fn fibonacci(delay: Duration) -> Strategy
Creates a retry strategy driven by a fibonacci back-off.
The specified duration will be multiplied by fib(n), where n is
the number of failed attempts.
Depending on the problem at hand, a fibonacci retry strategy might
perform better and lead to better throughput than the ExponentialBackoff
strategy.
See “A Performance Comparison of Different Backoff Algorithms under Different Rebroadcast Probabilities for MANETs.” for more details.
Sourcepub fn with_max_delay(self, duration: Duration) -> Self
pub fn with_max_delay(self, duration: Duration) -> Self
Sets the maximum delay between two attempts.
By default there is no maximum.
Sourcepub fn with_max_retries(self, retries: usize) -> Self
pub fn with_max_retries(self, retries: usize) -> Self
Sets the maximum number of retry attempts.
By default a retry will be attempted 5 times before giving up.
Sourcepub fn with_jitter(self, jitter: bool) -> Self
pub fn with_jitter(self, jitter: bool) -> Self
Enables or disables jitter on the delay.
Jitter will introduce a random variance to the retry strategy, which can be helpful to mitigate the “Thundering Herd” problem.