Struct phron_finality::sync::ticker::Ticker
source · pub struct Ticker {
last_reset: Instant,
mode: Mode,
max_timeout: Duration,
min_timeout: Duration,
}
Expand description
This struct is used for rate limiting as an on-demand ticker. It can be used for ticking
at most after max_timeout
but no sooner than after min_timeout
.
Example usage would be to use the wait
method in main select loop and
try_tick
whenever you would like to tick sooner in another branch of select,
resetting whenever the rate limited action actually occurs.
Fields§
§last_reset: Instant
§mode: Mode
§max_timeout: Duration
§min_timeout: Duration
Implementations§
source§impl Ticker
impl Ticker
sourcepub fn new(max_timeout: Duration, min_timeout: Duration) -> Self
pub fn new(max_timeout: Duration, min_timeout: Duration) -> Self
Returns new Ticker struct. Enforces max_timeout
>= min_timeout
.
sourcepub fn try_tick(&mut self) -> bool
pub fn try_tick(&mut self) -> bool
Returns whether at least min_timeout
time elapsed since the last reset.
If it has not, the next call to wait_and_tick
will return when min_timeout
elapses.
sourcepub async fn wait_and_tick(&mut self) -> bool
pub async fn wait_and_tick(&mut self) -> bool
Sleeps until next tick should happen.
Returns when enough time elapsed.
Returns whether max_timeout
elapsed since the last reset, and if so also resets.
§Cancel safety
This method is cancellation safe.
sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset the ticker, making it time from the moment of this call. Behaves as if it was just created with the same parametres.
fn since_reset(&self) -> Duration
async fn wait_current_timeout(&self)
Auto Trait Implementations§
impl RefUnwindSafe for Ticker
impl Send for Ticker
impl Sync for Ticker
impl Unpin for Ticker
impl UnwindSafe for Ticker
Blanket Implementations§
§impl<T> AnySync for T
impl<T> AnySync for T
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
§impl<T> CheckedConversion for T
impl<T> CheckedConversion for T
§fn checked_from<T>(t: T) -> Option<Self>where
Self: TryFrom<T>,
fn checked_from<T>(t: T) -> Option<Self>where
Self: TryFrom<T>,
§fn checked_into<T>(self) -> Option<T>where
Self: TryInto<T>,
fn checked_into<T>(self) -> Option<T>where
Self: TryInto<T>,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> IsType<T> for T
impl<T> IsType<T> for T
§impl<T, Outer> IsWrappedBy<Outer> for T
impl<T, Outer> IsWrappedBy<Outer> for T
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> SaturatedConversion for T
impl<T> SaturatedConversion for T
§fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
§fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
T
. Read more§impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
§fn unchecked_into(self) -> T
fn unchecked_into(self) -> T
unchecked_from
.§impl<T, S> UniqueSaturatedInto<T> for S
impl<T, S> UniqueSaturatedInto<T> for S
§fn unique_saturated_into(self) -> T
fn unique_saturated_into(self) -> T
T
.