Skip to main content

Scheduler

Struct Scheduler 

Source
pub struct Scheduler<E> { /* private fields */ }
Expand description

A scheduler for future events.

The scheduler does not dispatch events itself, rather it provides the facilities needed for the caller to efficiently dispatch events in as few wakeups as possible.

Implementations§

Source§

impl<E> Scheduler<E>

Source

pub fn add(&mut self, when: TimeRange, what: E) -> Handle<E>

Schedule an event to occur at a future point in time.

Returns a Handle which may be used to cancel or reschedule the event. The caller need not retain the Handle if cancellation and rescheduling are not required.

Source

pub fn clear(&mut self)

Cancel all pending events, leaving the scheduler idle.

Source

pub fn dispatch(&mut self, now: Instant) -> impl Iterator<Item = E> + use<E>

Removes events that are due to happen at or before now from the scheduler’s queue, returning an iterator over the removed events.

If the iterator is dropped before being fully consumed, it drops the remaining removed events.

Source

pub fn next_dispatch_range(&self) -> Option<TimeRange>

Returns the next time range in which Scheduler::dispatch should next be called to dispatch events.

Scheduler::dispatch should be called at some point in the returned TimeRange to dispatch events on time.

Calling dispatch closer to the end of the range is more efficient and results in more events being available. Calling dispatch before the returned range is inefficient but otherwise harmless.

The returned range may lie entirely in the past, if overdue events exists. The caller is expected to call Scheduler::dispatch as soon as possible in that case.

This method is intended to be used to plumb this Scheduler’s event dispatch into another Scheduler.

Source

pub fn next_dispatch(&self) -> Option<Instant>

Returns the next time at which Scheduler::dispatch should next be called to dispatch events.

This is the same as Scheduler::next_dispatch_range, but only returns the Instant corresponding to the end of the feasible time range.

Calling dispatch before the returned time is inefficient but otherwise harmless.

The returned time may be in the past, if overdue events exists. The caller is expected to call Scheduler::dispatch as soon as possible in that case.

This method is intended to be used to plumb this Scheduler into an external timer facility (e.g. std::thread::sleep, tokio::time::sleep), to trigger event dispatching at the appropriate time.

Trait Implementations§

Source§

impl<E: Debug> Debug for Scheduler<E>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<E> Default for Scheduler<E>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<E> Freeze for Scheduler<E>

§

impl<E> RefUnwindSafe for Scheduler<E>

§

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

§

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

§

impl<E> Unpin for Scheduler<E>

§

impl<E> UnsafeUnpin for Scheduler<E>

§

impl<E> UnwindSafe for Scheduler<E>

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.