pub struct MaybeBackoff { /* private fields */ }Expand description
MaybeBackoff provides a simplified way to manage an optional exponential backoff while giving control over when to wait.
§Example
ⓘ
let mut backoff = MaybeBackoff::default();
// Loop that runs fallible operation that should be retried with backoff.
loop {
backoff.sleep().await; // Does nothing when not armed (disarmed by default).
backoff.arm();
while let Some(event) = event_source.next().await {
match event {
Ok(Event::Open) => debug!("Connected!"),
Ok(Event::Message(event)) => match parse(event) {
Ok(data) => {
backoff.disarm();
forward_data(data).await;
break;
}
Err(error) => {
error!("Parsing failed: {error:?}");
event_source.close();
continue;
}
},
Err(error) => {
error!("Event source failed: {error:?}");
event_source.close();
continue;
}
}
}
}Implementations§
Trait Implementations§
Source§impl Default for MaybeBackoff
impl Default for MaybeBackoff
Source§fn default() -> MaybeBackoff
fn default() -> MaybeBackoff
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for MaybeBackoff
impl RefUnwindSafe for MaybeBackoff
impl Send for MaybeBackoff
impl Sync for MaybeBackoff
impl Unpin for MaybeBackoff
impl UnwindSafe for MaybeBackoff
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