pub struct BackoffTracker<T> { /* private fields */ }
Expand description
Tracks events that you don’t want to repeat very often, and lets you know when it’s safe to take the action that may cause those events.
Implementations§
Source§impl<T> BackoffTracker<T>
impl<T> BackoffTracker<T>
pub fn new(clock: Arc<dyn Clock>, config: BackoffConfig) -> Self
Source§impl<'t, T: Eq + Hash + 't> BackoffTracker<T>
High level management of code execution using backoff tracking primitives.
impl<'t, T: Eq + Hash + 't> BackoffTracker<T>
High level management of code execution using backoff tracking primitives.
Sourcepub fn backoff<F: Fn() -> X, X>(&mut self, id: T, f: F) -> Option<X>
pub fn backoff<F: Fn() -> X, X>(&mut self, id: T, f: F) -> Option<X>
Use this if you’d like to rate limit some code regardless of its outcome.
Triggers an event on any execution. see backoff_generic
.
Sourcepub fn backoff_singular<F: Fn() -> X, X>(&mut self, id: T, f: F) -> Option<X>
pub fn backoff_singular<F: Fn() -> X, X>(&mut self, id: T, f: F) -> Option<X>
Use this if you’d like to rate limit some code regardless of its outcome, but not if other events occur in between.
Triggers an event on any execution. see backoff_generic
and
singular_event
Sourcepub fn backoff_errors<F, O, E>(&mut self, id: T, f: F) -> Option<Result<O, E>>
pub fn backoff_errors<F, O, E>(&mut self, id: T, f: F) -> Option<Result<O, E>>
Use this if you’d like to rate limit some code when it fails.
Triggers an event on Err. see backoff_generic
.
Sourcepub fn backoff_oks<F, O, E>(&mut self, id: T, f: F) -> Option<Result<O, E>>
pub fn backoff_oks<F, O, E>(&mut self, id: T, f: F) -> Option<Result<O, E>>
Use this if you’d like to rate limit some code when it succeeds.
Triggers an event on Ok. see backoff_generic
.
Sourcepub fn backoff_generic<F, X, P>(
&mut self,
id: T,
f: F,
singular: bool,
predicate: P,
) -> Option<X>
pub fn backoff_generic<F, X, P>( &mut self, id: T, f: F, singular: bool, predicate: P, ) -> Option<X>
Generic function used by other backoff_
functions.
Run the code if ready. Trigger an event when the predicate is true Returns None if the execution was skipped due to not being ready.
Source§impl<'t, T: Eq + Hash + 't> BackoffTracker<T>
Primitives to track the backoff
impl<'t, T: Eq + Hash + 't> BackoffTracker<T>
Primitives to track the backoff
pub fn event(&mut self, item: T)
Sourcepub fn singular_event(&mut self, item: T)
pub fn singular_event(&mut self, item: T)
Like event
, but it clears all history of other events when a new event
is received.
Use this when you only need to backoff events that are consecutive duplicates, but don’t need to backoff events if different events occur in between.