pub struct BlockingRetry<B, T, E, F, SF = PleaseEnableAFeatureOrProvideACustomSleeper, RF = fn(&E) -> bool, NF = fn(&E, Duration)>{ /* private fields */ }Expand description
Retry structure generated by BlockingRetryable.
Implementations§
Source§impl<B, T, E, F, SF, RF, NF> BlockingRetry<B, T, E, F, SF, RF, NF>
impl<B, T, E, F, SF, RF, NF> BlockingRetry<B, T, E, F, SF, RF, NF>
Sourcepub fn sleep<SN>(self, sleep_fn: SN) -> BlockingRetry<B, T, E, F, SN, RF, NF>where
SN: BlockingSleeper,
pub fn sleep<SN>(self, sleep_fn: SN) -> BlockingRetry<B, T, E, F, SN, RF, NF>where
SN: BlockingSleeper,
Set the sleeper for retrying.
The sleeper should implement the BlockingSleeper trait. The simplest way is to use a closure like Fn(Duration).
If not specified, we use the DefaultBlockingSleeper.
§Examples
use anyhow::Result;
use backon::BlockingRetryable;
use backon::ExponentialBuilder;
fn fetch() -> Result<String> {
Ok("hello, world!".to_string())
}
fn main() -> Result<()> {
let retry = fetch
.retry(ExponentialBuilder::default())
.sleep(std::thread::sleep);
let content = retry.call()?;
println!("fetch succeeded: {}", content);
Ok(())
}Sourcepub fn when<RN>(self, retryable: RN) -> BlockingRetry<B, T, E, F, SF, RN, NF>
pub fn when<RN>(self, retryable: RN) -> BlockingRetry<B, T, E, F, SF, RN, NF>
Set the conditions for retrying.
If not specified, all errors are considered retryable.
§Examples
use anyhow::Result;
use backon::BlockingRetryable;
use backon::ExponentialBuilder;
fn fetch() -> Result<String> {
Ok("hello, world!".to_string())
}
fn main() -> Result<()> {
let retry = fetch
.retry(ExponentialBuilder::default())
.when(|e| e.to_string() == "EOF");
let content = retry.call()?;
println!("fetch succeeded: {}", content);
Ok(())
}Sourcepub fn notify<NN>(self, notify: NN) -> BlockingRetry<B, T, E, F, SF, RF, NN>
pub fn notify<NN>(self, notify: NN) -> BlockingRetry<B, T, E, F, SF, RF, NN>
Set to notify for all retry attempts.
When a retry happens, the input function will be invoked with the error and the sleep duration before pausing.
If not specified, this operation does nothing.
§Examples
use core::time::Duration;
use anyhow::Result;
use backon::BlockingRetryable;
use backon::ExponentialBuilder;
fn fetch() -> Result<String> {
Ok("hello, world!".to_string())
}
fn main() -> Result<()> {
let retry = fetch.retry(ExponentialBuilder::default()).notify(
|err: &anyhow::Error, dur: Duration| {
println!("retrying error {:?} with sleeping {:?}", err, dur);
},
);
let content = retry.call()?;
println!("fetch succeeded: {}", content);
Ok(())
}Auto Trait Implementations§
impl<B, T, E, F, SF, RF, NF> Freeze for BlockingRetry<B, T, E, F, SF, RF, NF>
impl<B, T, E, F, SF, RF, NF> RefUnwindSafe for BlockingRetry<B, T, E, F, SF, RF, NF>
impl<B, T, E, F, SF, RF, NF> Send for BlockingRetry<B, T, E, F, SF, RF, NF>
impl<B, T, E, F, SF, RF, NF> Sync for BlockingRetry<B, T, E, F, SF, RF, NF>
impl<B, T, E, F, SF, RF, NF> Unpin for BlockingRetry<B, T, E, F, SF, RF, NF>
impl<B, T, E, F, SF, RF, NF> UnwindSafe for BlockingRetry<B, T, E, F, SF, RF, NF>
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
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>
Wrap the input message
T in a tonic::Request