Struct retry_future::ExponentialRetryStrategy
source · pub struct ExponentialRetryStrategy {
pub base: usize,
pub max_attempts: usize,
pub initial_delay: Duration,
pub retry_early_returned_errors: bool,
}
Expand description
Retry futures exponentially.
Examples
use retry_future::RetryStrategy;
use retry_future::ExponentialRetryStrategy;
use std::time::Duration;
let mut strategy = ExponentialRetryStrategy {
base: 3,
max_attempts: 5,
initial_delay: Duration::from_secs(1),
..Default::default()
};
assert_eq!(strategy.check_attempt(0).unwrap(), Duration::from_secs(1));
assert_eq!(strategy.check_attempt(1).unwrap(), Duration::from_secs(3));
assert_eq!(strategy.check_attempt(2).unwrap(), Duration::from_secs(9));
assert_eq!(strategy.check_attempt(3).unwrap(), Duration::from_secs(27));
assert_eq!(strategy.check_attempt(4).unwrap(), Duration::from_secs(81));
assert!(strategy.check_attempt(5).is_err());
Fields§
§base: usize
§max_attempts: usize
§initial_delay: Duration
§retry_early_returned_errors: bool
Implementations§
source§impl ExponentialRetryStrategy
impl ExponentialRetryStrategy
pub fn new() -> Self
pub fn max_attempts(self, max_attempts: usize) -> Self
pub fn initial_delay(self, initial_delay: Duration) -> Self
sourcepub fn retry_early_returned_errors(
self,
retry_early_returned_errors: bool
) -> Self
pub fn retry_early_returned_errors(
self,
retry_early_returned_errors: bool
) -> Self
Trait Implementations§
source§impl Clone for ExponentialRetryStrategy
impl Clone for ExponentialRetryStrategy
source§fn clone(&self) -> ExponentialRetryStrategy
fn clone(&self) -> ExponentialRetryStrategy
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read more