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 fn with_jitter(self) -> FibonacciBuilder
pub fn with_jitter(self) -> FibonacciBuilder
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_min_delay(self, min_delay: Duration) -> FibonacciBuilder
pub fn with_min_delay(self, min_delay: Duration) -> FibonacciBuilder
Set the minimum delay for the backoff.
Sourcepub fn with_max_delay(self, max_delay: Duration) -> FibonacciBuilder
pub fn with_max_delay(self, max_delay: Duration) -> FibonacciBuilder
Set the maximum delay for the current backoff.
The delay will not increase if the current delay exceeds the maximum delay.
Sourcepub fn without_max_delay(self) -> FibonacciBuilder
pub fn without_max_delay(self) -> FibonacciBuilder
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 fn with_max_times(self, max_times: usize) -> FibonacciBuilder
pub fn with_max_times(self, max_times: usize) -> FibonacciBuilder
Set the maximum number of attempts for the current backoff.
The backoff will stop if the maximum number of attempts is reached.
Sourcepub fn without_max_times(self) -> FibonacciBuilder
pub fn without_max_times(self) -> FibonacciBuilder
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§fn build(self) -> <&FibonacciBuilder as BackoffBuilder>::Backoff
fn build(self) -> <&FibonacciBuilder as BackoffBuilder>::Backoff
Source§impl BackoffBuilder for FibonacciBuilder
impl BackoffBuilder for FibonacciBuilder
Source§fn build(self) -> <FibonacciBuilder as BackoffBuilder>::Backoff
fn build(self) -> <FibonacciBuilder as BackoffBuilder>::Backoff
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 moreSource§impl Debug for FibonacciBuilder
impl Debug for FibonacciBuilder
Source§impl Default for FibonacciBuilder
impl Default for FibonacciBuilder
Source§fn default() -> FibonacciBuilder
fn default() -> FibonacciBuilder
impl Copy for FibonacciBuilder
Auto Trait Implementations§
impl Freeze for FibonacciBuilder
impl RefUnwindSafe for FibonacciBuilder
impl Send for FibonacciBuilder
impl Sync for FibonacciBuilder
impl Unpin for FibonacciBuilder
impl UnwindSafe for FibonacciBuilder
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request