Strategy

Struct Strategy 

Source
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

Source

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.

Source

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.

Source

pub fn fixed(delay: Duration) -> Strategy

Creates a retry strategy driven by a fixed delay.

Source

pub fn with_max_delay(self, duration: Duration) -> Self

Sets the maximum delay between two attempts.

By default there is no maximum.

Source

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.

Source

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.

Source

pub fn retry<A: Action>(&self, action: A) -> Retry<A>

Run the given action, and use this strategy to retry on failure.

Source

pub fn retry_if<A: Action, C>(&self, action: A, condition: C) -> RetryIf<A, C>
where C: Condition<A::Error>,

Run the given action, and use this strategy to retry on failure if the error satisfies a given condition.

Trait Implementations§

Source§

impl Debug for Strategy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Strategy

Source§

fn default() -> Strategy

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.