pub struct GenericTimerService<MutexType: RawMutex> { /* private fields */ }
Expand description
An asynchronously awaitable timer.
The timer operates on millisecond precision and makes use of a configurable clock source.
The timer allows to wait asynchronously either for a certain duration,
or until the provided Clock
reaches a certain timestamp.
In order to unblock tasks that are waiting on the timer,
check_expirations
must be called in regular intervals on this timer service.
The timer can either be running on a separate timer thread (in case a thread-safe timer type is utilize), or it can be integrated into an executor in order to minimize context switches.
Implementations§
Source§impl<MutexType: RawMutex> GenericTimerService<MutexType>
impl<MutexType: RawMutex> GenericTimerService<MutexType>
Sourcepub fn new(clock: &'static dyn Clock) -> GenericTimerService<MutexType>
pub fn new(clock: &'static dyn Clock) -> GenericTimerService<MutexType>
Sourcepub fn next_expiration(&self) -> Option<u64>
pub fn next_expiration(&self) -> Option<u64>
Returns a timestamp when the next timer expires.
For thread-safe timers, the returned value is not precise and subject to race-conditions, since other threads can add timer in the meantime.
Therefore adding any timer to the GenericTimerService
should also
make sure to wake up the executor which polls for timeouts, in order to
let it capture the latest change.
Sourcepub fn check_expirations(&self)
pub fn check_expirations(&self)
Checks whether any of the attached TimerFuture
s has expired.
In this case the associated task is woken up.