Struct netstack3_base::LocalTimerHeap
source · 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.
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.