Skip to main content

ManualScheduler

Struct ManualScheduler 

Source
pub struct ManualScheduler { /* private fields */ }
Expand description

A clock that only moves when told to, like fake timers in JS tests.

Timers run in order of due time, then of creation; a repeating timer keeps its place among timers due at the same time (setInterval keeps its timer ID).

Implementations§

Source§

impl ManualScheduler

Source

pub fn new(now: f64) -> Rc<Self>

A clock at now, in milliseconds since 1970.

Source

pub fn run_checkpoints(&self)

Runs the pending checkpoints, as JS runs microtasks before a timer.

Source

pub fn pending_timers(&self) -> usize

The number of timers that have not fired or been cancelled.

Source

pub fn advance(&self, ms: f64)

Moves the clock forward by ms, firing every timer that comes due on the way, including ones those timers schedule.

Source

pub fn run_due_timers(&self)

Fires the timers due now, and the zero-delay timers they schedule, until none is left.

Trait Implementations§

Source§

impl Scheduler for ManualScheduler

Source§

fn checkpoint(&self, action: Box<dyn FnOnce()>)

Runs action before the next timer fires, or at the next run_checkpoints.

Source§

fn now(&self) -> f64

Milliseconds since 1970 (Date.now()).
Source§

fn monotonic_now(&self) -> f64

Milliseconds on a monotonic clock (performance.now()).
Source§

fn schedule(&self, ms: f64, action: Box<dyn FnOnce()>) -> Box<dyn Timer>

Calls action after ms milliseconds.
Source§

fn schedule_repeating( &self, ms: f64, action: Box<dyn FnMut()>, ) -> Box<dyn Timer>

Calls action every ms milliseconds until cancelled (setInterval).

Auto Trait Implementations§

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.