pub struct LocalTimerHeap<K, V, BT: TimerBindingsTypes + InstantBindingsTypes> { /* private fields */ }Expand description
A local timer heap that keeps timers for core modules.
LocalTimerHeap manages its wakeups through a TimerContext.
K is the key that timers are keyed on. V is optional sidecar data to be
kept with each timer.
Note that to provide fast timer deletion, LocalTimerHeap requires K to
be Clone and the implementation assumes that the clone is cheap.
Implementations§
Source§impl<K, V, BC> LocalTimerHeap<K, V, BC>
impl<K, V, BC> LocalTimerHeap<K, V, BC>
Sourcepub fn assert_timers(
&self,
timers: impl IntoIterator<Item = (K, V, BC::Instant)>,
)
pub fn assert_timers( &self, timers: impl IntoIterator<Item = (K, V, BC::Instant)>, )
Asserts installed timers with an iterator of (key, value, instant)
tuples.
Sourcepub fn assert_timers_after(
&self,
bindings_ctx: &mut BC,
timers: impl IntoIterator<Item = (K, V, Duration)>,
)
pub fn assert_timers_after( &self, bindings_ctx: &mut BC, timers: impl IntoIterator<Item = (K, V, Duration)>, )
Like LocalTimerHeap::assert_timers, but asserts based on a
duration after bindings_ctx.now().
Sourcepub fn assert_top(&mut self, key: &K, value: &V)
pub fn assert_top(&mut self, key: &K, value: &V)
Assets that the next time to fire has key and value.
Sourcepub fn assert_range<'a, R: RangeBounds<BC::Instant> + Debug, I: IntoIterator<Item = (&'a K, R)>>(
&'a self,
expect: I,
)
pub fn assert_range<'a, R: RangeBounds<BC::Instant> + Debug, I: IntoIterator<Item = (&'a K, R)>>( &'a self, expect: I, )
Asserts that the given timer is installed with an instant at the provided range.
Sourcepub fn assert_range_single<'a, R: RangeBounds<BC::Instant> + Debug>(
&'a self,
timer: &K,
range: R,
) -> (BC::Instant, &V)
pub fn assert_range_single<'a, R: RangeBounds<BC::Instant> + Debug>( &'a self, timer: &K, range: R, ) -> (BC::Instant, &V)
Asserts that the given timer is installed with an instant at the provided range, returning its information.
Source§impl<K, V, BC> LocalTimerHeap<K, V, BC>
impl<K, V, BC> LocalTimerHeap<K, V, BC>
Sourcepub fn new(bindings_ctx: &mut BC, dispatch_id: BC::DispatchId) -> Self
pub fn new(bindings_ctx: &mut BC, dispatch_id: BC::DispatchId) -> Self
Creates a new LocalTimerHeap with wakeup dispatch ID dispatch_id.
Sourcepub fn new_with_context<D, CC: CoreTimerContext<D, BC>>(
bindings_ctx: &mut BC,
dispatch_id: D,
) -> Self
pub fn new_with_context<D, CC: CoreTimerContext<D, BC>>( bindings_ctx: &mut BC, dispatch_id: D, ) -> Self
Like [new] but uses CC to covert the dispatch_id to match the type required by BC.
Sourcepub fn schedule_instant(
&mut self,
bindings_ctx: &mut BC,
timer: K,
value: V,
at: BC::Instant,
) -> Option<(BC::Instant, V)>
pub fn schedule_instant( &mut self, bindings_ctx: &mut BC, timer: K, value: V, at: BC::Instant, ) -> Option<(BC::Instant, V)>
Schedules timer with value at or after at.
If timer was already scheduled, returns the previously scheduled
instant and the associated value.
Sourcepub fn schedule_after(
&mut self,
bindings_ctx: &mut BC,
timer: K,
value: V,
after: Duration,
) -> Option<(BC::Instant, V)>
pub fn schedule_after( &mut self, bindings_ctx: &mut BC, timer: K, value: V, after: Duration, ) -> Option<(BC::Instant, V)>
Like [schedule_instant] but does the instant math from current time.
§Panics
Panics if the current BC::Instant cannot be represented by adding
duration after.
Sourcepub fn pop(&mut self, bindings_ctx: &mut BC) -> Option<(K, V)>
pub fn pop(&mut self, bindings_ctx: &mut BC) -> Option<(K, V)>
Pops an expired timer from the heap, if any.
Sourcepub fn get(&self, timer: &K) -> Option<(BC::Instant, &V)>
pub fn get(&self, timer: &K) -> Option<(BC::Instant, &V)>
Returns the scheduled instant and associated value for timer, if it’s
scheduled.
Sourcepub fn cancel(
&mut self,
bindings_ctx: &mut BC,
timer: &K,
) -> Option<(BC::Instant, V)>
pub fn cancel( &mut self, bindings_ctx: &mut BC, timer: &K, ) -> Option<(BC::Instant, V)>
Cancels timer, returning the scheduled instant and associated value if
any.
Trait Implementations§
Auto Trait Implementations§
impl<K, V, BT> Freeze for LocalTimerHeap<K, V, BT>
impl<K, V, BT> RefUnwindSafe for LocalTimerHeap<K, V, BT>where
<BT as TimerBindingsTypes>::Timer: RefUnwindSafe,
K: RefUnwindSafe,
<BT as InstantBindingsTypes>::Instant: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V, BT> Send for LocalTimerHeap<K, V, BT>
impl<K, V, BT> Sync for LocalTimerHeap<K, V, BT>
impl<K, V, BT> Unpin for LocalTimerHeap<K, V, BT>where
<BT as TimerBindingsTypes>::Timer: Unpin,
K: Unpin,
<BT as InstantBindingsTypes>::Instant: Unpin,
V: Unpin,
impl<K, V, BT> UnwindSafe for LocalTimerHeap<K, V, BT>where
<BT as TimerBindingsTypes>::Timer: UnwindSafe,
K: UnwindSafe,
<BT as InstantBindingsTypes>::Instant: UnwindSafe,
V: 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
§impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
§impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
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