Trait vector_core::time::KeyedTimer
source · pub trait KeyedTimer<K> {
// Required methods
fn clear(&mut self);
fn insert(&mut self, item_key: K);
fn remove(&mut self, item_key: &K);
fn poll_expired(&mut self, cx: &mut Context<'_>) -> Poll<Option<K>>;
}
Expand description
A trait for representing a timer which holds multiple subtimers, mapped by an arbitrary key, K
.
Embedding time as a type into other types eases property testing and verification. As such, this trait represents the minimum functionality required to describe management of keyed timers for the types implemented in this crate that require such behavior.
Users can look at vector_stream::batcher::ExpirationQueue
for a concrete implementation.
Required Methods§
sourcefn clear(&mut self)
fn clear(&mut self)
Clear the timer.
Clears all keys from the timer. Future calls to poll_expired
will return None
until
another key is added.
sourcefn insert(&mut self, item_key: K)
fn insert(&mut self, item_key: K)
Insert a new subtimer, keyed by K
.
If the given key already exists in the timer, the underlying subtimer is reset.
sourcefn poll_expired(&mut self, cx: &mut Context<'_>) -> Poll<Option<K>>
fn poll_expired(&mut self, cx: &mut Context<'_>) -> Poll<Option<K>>
Attempts to pull out the next expired subtimer in the queue.
The key of the subtimer is returned if it has expired, otherwise, returns None
if the
the queue is exhausted.
Unlike a typical stream, returning None
only indicates that the queue
is empty, not that the queue will never return anything else in the future.
Used primarily for property testing vis-á-vis vector_stream::batcher::Batcher
.