Struct BackoffTracker

Source
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>

Source

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.

Source

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.

Source

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

Source

pub fn backoff_errors<F, O, E>(&mut self, id: T, f: F) -> Option<Result<O, E>>
where F: Fn() -> 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.

Source

pub fn backoff_oks<F, O, E>(&mut self, id: T, f: F) -> Option<Result<O, E>>
where F: Fn() -> 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.

Source

pub fn backoff_generic<F, X, P>( &mut self, id: T, f: F, singular: bool, predicate: P, ) -> Option<X>
where F: Fn() -> X, P: Fn(&X) -> bool,

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

Source

pub fn event(&mut self, item: T)

Source

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.

Source

pub fn clear(&mut self, item: &T)

Source

pub fn clear_many<'a>(&mut self, items: impl IntoIterator<Item = &'a T>)
where 't: 'a,

Source

pub fn is_ready(&self, item: &T) -> bool

Trait Implementations§

Source§

impl<T> Default for BackoffTracker<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for BackoffTracker<T>

§

impl<T> !RefUnwindSafe for BackoffTracker<T>

§

impl<T> Send for BackoffTracker<T>
where T: Send,

§

impl<T> Sync for BackoffTracker<T>
where T: Sync,

§

impl<T> Unpin for BackoffTracker<T>
where T: Unpin,

§

impl<T> !UnwindSafe for BackoffTracker<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ProvideA for T

Source§

fn provide_a<T>(&self) -> T
where Self: Provides<T>,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more