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: boolImplementations§
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 duplicate 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 moreSource§impl Debug for ExponentialRetryStrategy
impl Debug for ExponentialRetryStrategy
Source§impl Default for ExponentialRetryStrategy
impl Default for ExponentialRetryStrategy
Source§impl RetryStrategy for ExponentialRetryStrategy
impl RetryStrategy for ExponentialRetryStrategy
Source§fn check_attempt(
&mut self,
attempts_before: usize,
) -> Result<Duration, TooManyAttempts>
fn check_attempt( &mut self, attempts_before: usize, ) -> Result<Duration, TooManyAttempts>
attempts_before means how many attempts a future
was trying to resolve to Ok(_) after returning Err(_).Source§fn retry_early_returned_errors(&self) -> bool
fn retry_early_returned_errors(&self) -> bool
impl Copy for ExponentialRetryStrategy
Auto Trait Implementations§
impl Freeze for ExponentialRetryStrategy
impl RefUnwindSafe for ExponentialRetryStrategy
impl Send for ExponentialRetryStrategy
impl Sync for ExponentialRetryStrategy
impl Unpin for ExponentialRetryStrategy
impl UnwindSafe for ExponentialRetryStrategy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more