pub struct ConstantBuilder { /* private fields */ }
Expand description
导出 backon 实现失败重试
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 const fn new() -> ConstantBuilder
pub const fn new() -> ConstantBuilder
Create a new ConstantBuilder
with default values.
Sourcepub const fn with_delay(self, delay: Duration) -> ConstantBuilder
pub const fn with_delay(self, delay: Duration) -> ConstantBuilder
Set the delay for the backoff.
Sourcepub const fn with_max_times(self, max_times: usize) -> ConstantBuilder
pub const fn with_max_times(self, max_times: usize) -> ConstantBuilder
Set the maximum number of attempts to be made.
Sourcepub const fn with_jitter(self) -> ConstantBuilder
pub const fn with_jitter(self) -> ConstantBuilder
Enable jitter for the backoff.
Jitter is a random value added to the delay to prevent a thundering herd problem.
Sourcepub fn with_jitter_seed(self, seed: u64) -> ConstantBuilder
pub fn with_jitter_seed(self, seed: u64) -> ConstantBuilder
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 without_max_times(self) -> ConstantBuilder
pub const fn without_max_times(self) -> ConstantBuilder
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§fn build(self) -> <&ConstantBuilder as BackoffBuilder>::Backoff
fn build(self) -> <&ConstantBuilder as BackoffBuilder>::Backoff
Construct a new backoff using the builder.
Source§impl BackoffBuilder for ConstantBuilder
impl BackoffBuilder for ConstantBuilder
Source§fn build(self) -> <ConstantBuilder as BackoffBuilder>::Backoff
fn build(self) -> <ConstantBuilder as BackoffBuilder>::Backoff
Construct a new backoff using the builder.
Source§impl Clone for ConstantBuilder
impl Clone for ConstantBuilder
Source§fn clone(&self) -> ConstantBuilder
fn clone(&self) -> ConstantBuilder
Returns a duplicate 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
Source§fn default() -> ConstantBuilder
fn default() -> ConstantBuilder
Returns the “default value” for a type. Read more
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