Trait netstack3_base::TimerContext
source · pub trait TimerContext: InstantContext + TimerBindingsTypes {
// Required methods
fn new_timer(&mut self, id: Self::DispatchId) -> Self::Timer;
fn schedule_timer_instant(
&mut self,
time: Self::Instant,
timer: &mut Self::Timer,
) -> Option<Self::Instant>;
fn cancel_timer(&mut self, timer: &mut Self::Timer) -> Option<Self::Instant>;
fn scheduled_instant(
&self,
timer: &mut Self::Timer,
) -> Option<Self::Instant>;
fn unique_timer_id(&self, timer: &Self::Timer) -> Self::UniqueTimerId;
// Provided method
fn schedule_timer(
&mut self,
duration: Duration,
timer: &mut Self::Timer,
) -> Option<Self::Instant> { ... }
}
Expand description
A context providing time scheduling to core.
Required Methods§
sourcefn new_timer(&mut self, id: Self::DispatchId) -> Self::Timer
fn new_timer(&mut self, id: Self::DispatchId) -> Self::Timer
Creates a new timer that dispatches id
back to core when fired.
Creating a new timer is an expensive operation and should be used
sparingly. Modules should prefer to create a timer on creation and then
schedule/reschedule it as needed. For modules with very dynamic timers,
a [LocalTimerHeap
] tied to a larger Timer
might be a better
alternative than creating many timers.
sourcefn schedule_timer_instant(
&mut self,
time: Self::Instant,
timer: &mut Self::Timer,
) -> Option<Self::Instant>
fn schedule_timer_instant( &mut self, time: Self::Instant, timer: &mut Self::Timer, ) -> Option<Self::Instant>
Schedule a timer to fire at some point in the future. Returns the previously scheduled instant, if this timer was scheduled.
sourcefn cancel_timer(&mut self, timer: &mut Self::Timer) -> Option<Self::Instant>
fn cancel_timer(&mut self, timer: &mut Self::Timer) -> Option<Self::Instant>
Cancel a timer.
Cancels timer
, returning the instant it was scheduled for if it was
scheduled.
Note that there’s no guarantee that observing None
means that the
dispatch procedure for a previously fired timer has already concluded.
It is possible to observe None
here while the DispatchId
timer
was created with is still making its way to the module that originally
scheduled this timer. If Some
is observed, however, then the
TimerContext
guarantees this timer
will not fire until
[schedule_timer_instant
] is called to reschedule it.
sourcefn scheduled_instant(&self, timer: &mut Self::Timer) -> Option<Self::Instant>
fn scheduled_instant(&self, timer: &mut Self::Timer) -> Option<Self::Instant>
Get the instant a timer will fire, if one is scheduled.
sourcefn unique_timer_id(&self, timer: &Self::Timer) -> Self::UniqueTimerId
fn unique_timer_id(&self, timer: &Self::Timer) -> Self::UniqueTimerId
Retrieves the timer id for timer
.
This can be used with TimerHandler::handle_timer
to match a
[Self::Timer
] instance with a firing event.