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