pub struct FibonacciBuilder { /* private fields */ }
Expand description
FibonacciBuilder is used to build a [FibonacciBackoff
] which offers a delay with Fibonacci-based retries.
§Default
- jitter: false
- min_delay: 1s
- max_delay: 60s
- max_times: 3
§Examples
use anyhow::Result;
use backon::FibonacciBuilder;
use backon::Retryable;
async fn fetch() -> Result<String> {
Ok(reqwest::get("https://www.rust-lang.org")
.await?
.text()
.await?)
}
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
let content = fetch.retry(FibonacciBuilder::default()).await?;
println!("fetch succeeded: {}", content);
Ok(())
}
Implementations§
Source§impl FibonacciBuilder
impl FibonacciBuilder
Sourcepub const fn with_jitter(self) -> Self
pub const fn with_jitter(self) -> Self
Set the jitter for the backoff.
When jitter is enabled, FibonacciBackoff will add a random jitter between (0, min_delay)
to the delay.
Sourcepub fn with_jitter_seed(self, seed: u64) -> Self
pub fn with_jitter_seed(self, seed: u64) -> Self
Set the seed value for the jitter random number generator. If no seed is given, a random seed is used in std and default seed is used in no_std.
Sourcepub const fn with_min_delay(self, min_delay: Duration) -> Self
pub const fn with_min_delay(self, min_delay: Duration) -> Self
Set the minimum delay for the backoff.
Sourcepub const fn with_max_delay(self, max_delay: Duration) -> Self
pub const fn with_max_delay(self, max_delay: Duration) -> Self
Set the maximum delay for the current backoff.
The delay will not increase if the current delay exceeds the maximum delay.
Sourcepub const fn without_max_delay(self) -> Self
pub const fn without_max_delay(self) -> Self
Set no maximum delay for the backoff.
The delay will keep increasing.
The delay will saturate at Duration::MAX
which is an unrealistic delay.
Sourcepub const fn with_max_times(self, max_times: usize) -> Self
pub const fn with_max_times(self, max_times: usize) -> Self
Set the maximum number of attempts for the current backoff.
The backoff will stop if the maximum number of attempts is reached.
Sourcepub const fn without_max_times(self) -> Self
pub const fn without_max_times(self) -> Self
Set no maximum number of attempts for the current backoff.
The backoff will not stop by itself.
The backoff could stop reaching usize::MAX
attempts but this is unrealistic.
Trait Implementations§
Source§impl BackoffBuilder for &FibonacciBuilder
impl BackoffBuilder for &FibonacciBuilder
Source§impl BackoffBuilder for FibonacciBuilder
impl BackoffBuilder for FibonacciBuilder
Source§impl Clone for FibonacciBuilder
impl Clone for FibonacciBuilder
Source§fn clone(&self) -> FibonacciBuilder
fn clone(&self) -> FibonacciBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more