pub struct Backoff {
base_delay: u64,
max_delay: u64,
retries: AtomicU32,
stop: AtomicBool,
}
Expand description
Exponential backoff https://en.wikipedia.org/wiki/Exponential_backoff
§Examples
use karyon_core::async_util::Backoff;
async {
let backoff = Backoff::new(300, 3000);
loop {
backoff.sleep().await;
// do something
break;
}
backoff.reset();
// ....
};
Fields§
§base_delay: u64
The base delay in milliseconds for the initial retry.
max_delay: u64
The max delay in milliseconds allowed for a retry.
retries: AtomicU32
Atomic counter
stop: AtomicBool
Stop flag
Implementations§
Auto Trait Implementations§
impl !Freeze for Backoff
impl RefUnwindSafe for Backoff
impl Send for Backoff
impl Sync for Backoff
impl Unpin for Backoff
impl UnwindSafe for Backoff
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