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§

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
attempts_before means how many attempts a future was trying to resolve to Ok(_) after returning Err(_). Read more
If true, errors propagated using ? inside a future will be retried. 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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
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.