pub struct Backoff { /* private fields */ }Expand description
Delays between attempts: first, doubling each attempt up to max, each one
drawn from the upper half of its step when jitter is on, so retries spread out
but never come faster than half the step (D-142).
use net_io::Backoff;
use std::time::Duration;
let mut b = Backoff::new()
.first(Duration::from_millis(100))
.max(Duration::from_secs(2))
.jitter(false)
.attempts(3);
assert_eq!(b.next_delay(), Some(Duration::from_millis(100)));
assert_eq!(b.next_delay(), Some(Duration::from_millis(200)));
assert_eq!(b.next_delay(), Some(Duration::from_millis(400)));
assert_eq!(b.next_delay(), None);
b.reset();
assert_eq!(b.attempt(), 0);Implementations§
Source§impl Backoff
impl Backoff
Sourcepub fn jitter(self, on: bool) -> Backoff
pub fn jitter(self, on: bool) -> Backoff
Whether each delay is drawn from the upper half of its step (on by default).
Sourcepub fn attempts(self, n: u32) -> Backoff
pub fn attempts(self, n: u32) -> Backoff
At most n delays; then Backoff::next_delay returns None.
Sourcepub fn give_up_after(self, total: Duration) -> Backoff
pub fn give_up_after(self, total: Duration) -> Backoff
next_delay returns None once waiting the next delay would end later
than total after the first call.
Sourcepub fn next_delay(&mut self) -> Option<Duration>
pub fn next_delay(&mut self) -> Option<Duration>
The delay before the next attempt, or None when the attempts or the time
are spent.
Trait Implementations§
Auto Trait Implementations§
impl Forget for Backoff
impl Freeze for Backoff
impl Move for Backoff
impl RefUnwindSafe for Backoff
impl Send for Backoff
impl Sync for Backoff
impl Unpin for Backoff
impl UnsafeUnpin 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