pub struct TimerService { /* private fields */ }Expand description
Timer service for scheduling and managing timers.
The timer service maintains a priority queue of timer registrations, ordered by timestamp. Operators can register timers to be fired at specific event times.
§Example
use laminar_core::time::{TimerService, TimerKey};
let mut service = TimerService::new();
// Register timers at different times
let id1 = service.register_timer(100, None, None);
let id2 = service.register_timer(50, Some(TimerKey::from_slice(&[1, 2, 3])), None);
// Poll for timers that should fire at time 75
let fired = service.poll_timers(75);
assert_eq!(fired.len(), 1);
assert_eq!(fired[0].id, id2); // Timer at t=50 fires firstImplementations§
Source§impl TimerService
impl TimerService
Sourcepub fn register_timer(
&mut self,
timestamp: i64,
key: Option<TimerKey>,
operator_index: Option<usize>,
) -> u64
pub fn register_timer( &mut self, timestamp: i64, key: Option<TimerKey>, operator_index: Option<usize>, ) -> u64
Registers a new timer.
Returns the unique timer ID that can be used to cancel the timer.
§Arguments
timestamp- The event time at which the timer should firekey- Optional key for keyed operatorsoperator_index- Optional index of the operator registering the timer(must match the index in the reactor)
Sourcepub fn poll_timers(&mut self, current_time: i64) -> FiredTimersVec
pub fn poll_timers(&mut self, current_time: i64) -> FiredTimersVec
Polls for timers that should fire at or before the given timestamp.
Returns all timers with timestamps <= current_time, in order.
Uses FiredTimersVec (SmallVec) to avoid heap allocation when few timers fire.
§Panics
This function should not panic under normal circumstances. The internal
expect is only called after verifying the heap is not empty via peek.
Sourcepub fn cancel_timer(&mut self, id: u64) -> bool
pub fn cancel_timer(&mut self, id: u64) -> bool
Cancels a timer by ID.
Returns true if the timer was found and cancelled.
Sourcepub fn pending_count(&self) -> usize
pub fn pending_count(&self) -> usize
Returns the number of pending timers.
Sourcepub fn next_timer_timestamp(&self) -> Option<i64>
pub fn next_timer_timestamp(&self) -> Option<i64>
Returns the timestamp of the next timer to fire, if any.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TimerService
impl RefUnwindSafe for TimerService
impl Send for TimerService
impl Sync for TimerService
impl Unpin for TimerService
impl UnwindSafe for TimerService
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.