futures_intrusive::timer

Struct GenericTimerService

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

Source

pub fn new(clock: &'static dyn Clock) -> GenericTimerService<MutexType>

Creates a new Timer in the given state.

The Timer will query the provided Clock instance for the current time whenever required.

In order to create a create a clock which utilizes system time, StdClock can be utilized. In order to simulate time for test purposes, MockClock can be utilized.

Source

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.

Source

pub fn check_expirations(&self)

Checks whether any of the attached TimerFutures has expired. In this case the associated task is woken up.

Trait Implementations§

Source§

impl<MutexType: RawMutex> Debug for GenericTimerService<MutexType>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<MutexType: RawMutex> LocalTimer for GenericTimerService<MutexType>

Source§

fn delay(&self, delay: Duration) -> LocalTimerFuture<'_>

Returns a future that gets fulfilled after the given Duration

Source§

fn deadline(&self, timestamp: u64) -> LocalTimerFuture<'_>

Returns a future that gets fulfilled when the utilized Clock reaches the given timestamp.

Source§

impl<MutexType> Timer for GenericTimerService<MutexType>
where MutexType: Sync + RawMutex,

Source§

fn delay(&self, delay: Duration) -> TimerFuture<'_>

Returns a future that gets fulfilled after the given Duration

Source§

fn deadline(&self, timestamp: u64) -> TimerFuture<'_>

Returns a future that gets fulfilled when the utilized Clock reaches the given timestamp.

Source§

impl<MutexType: RawMutex + Send> Send for GenericTimerService<MutexType>

Source§

impl<MutexType: RawMutex + Sync> Sync for GenericTimerService<MutexType>

Auto Trait Implementations§

§

impl<MutexType> !Freeze for GenericTimerService<MutexType>

§

impl<MutexType> !RefUnwindSafe for GenericTimerService<MutexType>

§

impl<MutexType> Unpin for GenericTimerService<MutexType>
where MutexType: Unpin,

§

impl<MutexType> !UnwindSafe for GenericTimerService<MutexType>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.