pub struct TimerHeap<T> { /* private fields */ }
Expand description
Store timers in a binary heap. Keep them sorted by which timer is going to expire first.
Implementations§
Source§impl<T: Eq + Clone + Hash> TimerHeap<T>
impl<T: Eq + Clone + Hash> TimerHeap<T>
Sourcepub fn insert(
&mut self,
key: T,
duration: Duration,
ty: TimerType,
) -> Result<(), Error>
pub fn insert( &mut self, key: T, duration: Duration, ty: TimerType, ) -> Result<(), Error>
Insert a timer into the heap
Return an error if the key already exists.
Sourcepub fn upsert(&mut self, key: T, duration: Duration, ty: TimerType) -> bool
pub fn upsert(&mut self, key: T, duration: Duration, ty: TimerType) -> bool
Insert a timer into the heap, replacing any existing timer if one exists
Return true if a timer already existed in the heap, false otherwise
Sourcepub fn remove(&mut self, key: T) -> bool
pub fn remove(&mut self, key: T) -> bool
Remove a TimerEnry by Id
Return true if it exists, false otherwise
Sourcepub fn time_remaining(&self) -> Option<Duration>
pub fn time_remaining(&self) -> Option<Duration>
Return the amount of time remaining for the earliest expiring timer.
Return None
if there are no timers in the heap.
Sourcepub fn earliest_timeout(&self, user_timeout: Duration) -> Duration
pub fn earliest_timeout(&self, user_timeout: Duration) -> Duration
Return the earliest timeout based on a user timeout and the least remaining time in the next timer to fire.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for TimerHeap<T>
impl<T> RefUnwindSafe for TimerHeap<T>where
T: RefUnwindSafe,
impl<T> Send for TimerHeap<T>where
T: Send,
impl<T> Sync for TimerHeap<T>where
T: Sync,
impl<T> Unpin for TimerHeap<T>where
T: Unpin,
impl<T> UnwindSafe for TimerHeap<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more