pub struct ConstantBuilder { /* private fields */ }
Expand description
ConstantBuilder is used to create a [ConstantBackoff
], providing a steady delay with a fixed number of retries.
§Default
- delay: 1s
- max_times: 3
§Examples
use anyhow::Result;
use backon::ConstantBuilder;
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(ConstantBuilder::default()).await?;
println!("fetch succeeded: {}", content);
Ok(())
}
Implementations§
Source§impl ConstantBuilder
impl ConstantBuilder
Sourcepub fn with_delay(self, delay: Duration) -> Self
pub fn with_delay(self, delay: Duration) -> Self
Set the delay for the backoff.
Sourcepub fn with_max_times(self, max_times: usize) -> Self
pub fn with_max_times(self, max_times: usize) -> Self
Set the maximum number of attempts to be made.
Sourcepub fn with_jitter(self) -> Self
pub fn with_jitter(self) -> Self
Set jitter for the backoff.
Jitter is a random value added to the delay to prevent a thundering herd problem.
Sourcepub fn without_max_times(self) -> Self
pub fn without_max_times(self) -> Self
Set no max times for the 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 &ConstantBuilder
impl BackoffBuilder for &ConstantBuilder
Source§impl BackoffBuilder for ConstantBuilder
impl BackoffBuilder for ConstantBuilder
Source§impl Clone for ConstantBuilder
impl Clone for ConstantBuilder
Source§fn clone(&self) -> ConstantBuilder
fn clone(&self) -> ConstantBuilder
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for ConstantBuilder
impl Debug for ConstantBuilder
Source§impl Default for ConstantBuilder
impl Default for ConstantBuilder
impl Copy for ConstantBuilder
Auto Trait Implementations§
impl Freeze for ConstantBuilder
impl RefUnwindSafe for ConstantBuilder
impl Send for ConstantBuilder
impl Sync for ConstantBuilder
impl Unpin for ConstantBuilder
impl UnwindSafe for ConstantBuilder
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
Mutably borrows from an owned value. Read more