Struct futures_backoff::Strategy
[−]
[src]
pub struct Strategy { /* fields omitted */ }
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) });
Methods
impl Strategy
[src]
pub fn exponential(delay: Duration) -> Strategy
[src]
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.
pub fn fibonacci(delay: Duration) -> Strategy
[src]
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.
pub fn fixed(delay: Duration) -> Strategy
[src]
Creates a retry strategy driven by a fixed delay.
pub fn with_max_delay(self, duration: Duration) -> Self
[src]
Sets the maximum delay between two attempts.
By default there is no maximum.
pub fn with_max_retries(self, retries: usize) -> Self
[src]
Sets the maximum number of retry attempts.
By default a retry will be attempted 5 times before giving up.
pub fn with_jitter(self, jitter: bool) -> Self
[src]
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.
pub fn retry<A: Action>(&self, action: A) -> Retry<A>
[src]
Run the given action, and use this strategy to retry on failure.
pub fn retry_if<A: Action, C>(&self, action: A, condition: C) -> RetryIf<A, C> where
C: Condition<A::Error>,
[src]
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
impl Debug for Strategy
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more