pub struct BackoffSchedule<B> { /* private fields */ }Available on crate feature
backoff only.Expand description
Backs off using a BackoffSchedule from the backoff crate.
Implemented for tasks returning a Result. If the result is Ok, the backoff will be reset.
If the result is Err, or the job panics, the backoff increments.
Implementations§
Source§impl<B: Backoff> BackoffSchedule<B>
impl<B: Backoff> BackoffSchedule<B>
Sourcepub fn from_backoff(backoff: B) -> Self
pub fn from_backoff(backoff: B) -> Self
Creates a BackoffSchedule using the given backoff policy.
use backoff::{ExponentialBackoff, ExponentialBackoffBuilder};
use periodically::{Schedule, BackoffSchedule};
use std::time::Duration;
let backoff: ExponentialBackoff = ExponentialBackoffBuilder::new().build();
let backoff_schedule = BackoffSchedule::from_backoff(backoff);
assert_eq!(backoff_schedule.initial(), Some(Duration::from_secs(0)));
assert!(backoff_schedule.next(Err(())).unwrap() < Duration::from_secs(1));Trait Implementations§
Source§impl<T, E, B: Backoff + Send> Schedule<Result<T, E>> for BackoffSchedule<B>
impl<T, E, B: Backoff + Send> Schedule<Result<T, E>> for BackoffSchedule<B>
Source§fn next(&self, task_output: Result<T, E>) -> Option<Duration>
fn next(&self, task_output: Result<T, E>) -> Option<Duration>
Returns the time until this task should be scheduled again.
None indicates that this task should never run again.
task_output is the last return value of the task, which
can be ignored if desired.Source§fn next_on_task_panic(&self) -> Option<Duration>
fn next_on_task_panic(&self) -> Option<Duration>
Returns the time until this task should be scheduled again.
Only called when the previous task execution fails to return
a value. By default, implemented as Schedule::initial.
Auto Trait Implementations§
impl<B> !Freeze for BackoffSchedule<B>
impl<B> !RefUnwindSafe for BackoffSchedule<B>
impl<B> Send for BackoffSchedule<B>where
B: Send,
impl<B> !Sync for BackoffSchedule<B>
impl<B> Unpin for BackoffSchedule<B>where
B: Unpin,
impl<B> UnwindSafe for BackoffSchedule<B>where
B: UnwindSafe,
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