pub struct Scheduler<E> { /* private fields */ }Expand description
The worker-owned deadline heap + its raise channel. Construct with
Scheduler::new, hand SchedulerHandles to raisers, then call
Scheduler::run on the worker thread.
Implementations§
Source§impl<E> Scheduler<E>
impl<E> Scheduler<E>
Sourcepub fn new(idle_floor: Duration) -> (Self, SchedulerHandle<E>)
pub fn new(idle_floor: Duration) -> (Self, SchedulerHandle<E>)
Creates a scheduler and a handle factory. idle_floor bounds the park
when nothing is scheduled (e.g. 1 s).
Sourcepub fn park_due_batch(&mut self) -> (Vec<E>, bool)
pub fn park_due_batch(&mut self) -> (Vec<E>, bool)
One park step for callers that want to run their own batch logic (e.g.
coalesce many raised events into a single run_tick_iteration): drains
the channel, then if nothing is due, parks until the earliest deadline or
a raise. Returns every now-due event (earliest first) plus a stop flag.
Unlike Self::run, the caller decides what to do with the batch — so N
raised wake-events collapse into one unit of work.
Sourcepub fn run<F: FnMut(E)>(&mut self, dispatch: F)
pub fn run<F: FnMut(E)>(&mut self, dispatch: F)
Runs the worker loop on the calling thread until a Stop is received and
all already-due events are dispatched, or the channel disconnects.
dispatch is called for each fired event (earliest-deadline first). It
may itself call SchedulerHandle::raise_* to re-arm periodic events —
those land in the channel and are drained on the next loop turn.