pub enum RetryPolicy {
Count {
attempts: u32,
should_retry: Option<Arc<dyn Fn(&Response) -> bool + Sync + Send>>,
},
Linear {
attempts: u32,
delay: Duration,
should_retry: Option<Arc<dyn Fn(&Response) -> bool + Sync + Send>>,
jitter: bool,
},
Exponential {
attempts: u32,
base_delay: Duration,
max_delay: Duration,
should_retry: Option<Arc<dyn Fn(&Response) -> bool + Sync + Send>>,
jitter: bool,
},
}Expand description
Retry policy configuration.
The attempts value is the maximum number of retries after the initial request.
For example, RetryPolicy::count(2) performs up to three HTTP calls (one initial + two retries).
§Examples
use better_fetch::RetryPolicy;
// Up to 3 HTTP calls total (1 initial + 2 retries), 1s between attempts
let policy = RetryPolicy::count(2);
assert_eq!(policy.max_attempts(), 2);Variants§
Count
Shorthand for linear retry with attempts retries and a 1 second delay between attempts.
Fields
Linear
Fixed delay between retries.
Fields
jitter: boolWhen true, randomizes delay (see Self::with_jitter).
Exponential
Exponential backoff capped at max_delay.
Implementations§
Source§impl RetryPolicy
impl RetryPolicy
Sourcepub fn count(attempts: u32) -> RetryPolicy
pub fn count(attempts: u32) -> RetryPolicy
Shorthand: attempts retries with 1 second delay and default status codes.
Sourcepub fn linear(attempts: u32, delay: Duration) -> RetryPolicy
pub fn linear(attempts: u32, delay: Duration) -> RetryPolicy
Linear backoff with a fixed delay between retries.
Sourcepub fn exponential(
attempts: u32,
base_delay: Duration,
max_delay: Duration,
) -> RetryPolicy
pub fn exponential( attempts: u32, base_delay: Duration, max_delay: Duration, ) -> RetryPolicy
Exponential backoff from base_delay up to max_delay (jitter enabled by default).
Sourcepub fn with_jitter(self, jitter: bool) -> RetryPolicy
pub fn with_jitter(self, jitter: bool) -> RetryPolicy
Enables randomized backoff jitter on linear or exponential policies.
Sourcepub fn with_should_retry(
self,
f: Arc<dyn Fn(&Response) -> bool + Sync + Send>,
) -> RetryPolicy
pub fn with_should_retry( self, f: Arc<dyn Fn(&Response) -> bool + Sync + Send>, ) -> RetryPolicy
Overrides the default retry predicate (408, 429, 502, 503, 504).
Sourcepub fn max_attempts(&self) -> u32
pub fn max_attempts(&self) -> u32
Returns the maximum number of retries after the initial request.
Trait Implementations§
Source§impl Clone for RetryPolicy
impl Clone for RetryPolicy
Source§fn clone(&self) -> RetryPolicy
fn clone(&self) -> RetryPolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more