Skip to main content

Scheduler

Struct Scheduler 

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

Source

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).

Source

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.

Source

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.

Auto Trait Implementations§

§

impl<E> !Sync for Scheduler<E>

§

impl<E> Freeze for Scheduler<E>

§

impl<E> RefUnwindSafe for Scheduler<E>
where E: RefUnwindSafe,

§

impl<E> Send for Scheduler<E>
where E: Send,

§

impl<E> Unpin for Scheduler<E>
where E: Unpin,

§

impl<E> UnsafeUnpin for Scheduler<E>

§

impl<E> UnwindSafe for Scheduler<E>
where E: UnwindSafe,

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.