pub struct Scheduler<C: Clock = WallClock> { /* private fields */ }Expand description
The deterministic event loop scheduler state.
Implementations§
Source§impl<C: Clock> Scheduler<C>
impl<C: Clock> Scheduler<C>
Sourcepub fn with_clock(clock: C) -> Self
pub fn with_clock(clock: C) -> Self
Create a new scheduler with a custom clock.
Sourcepub const fn current_seq(&self) -> Seq
pub const fn current_seq(&self) -> Seq
Get the current sequence number.
Sourcepub fn has_pending(&self) -> bool
pub fn has_pending(&self) -> bool
Check if there are pending tasks.
Sourcepub fn macrotask_count(&self) -> usize
pub fn macrotask_count(&self) -> usize
Get the number of pending macrotasks.
Sourcepub fn timer_count(&self) -> usize
pub fn timer_count(&self) -> usize
Get the number of pending timers.
Sourcepub fn set_timeout(&mut self, delay_ms: u64) -> u64
pub fn set_timeout(&mut self, delay_ms: u64) -> u64
Schedule a timer to fire at the given deadline.
Returns the timer ID for cancellation.
Sourcepub fn clear_timeout(&mut self, timer_id: u64) -> bool
pub fn clear_timeout(&mut self, timer_id: u64) -> bool
Cancel a timer by ID.
Returns true if the timer was found and cancelled.
Sourcepub fn enqueue_hostcall_complete(
&mut self,
call_id: String,
outcome: HostcallOutcome,
)
pub fn enqueue_hostcall_complete( &mut self, call_id: String, outcome: HostcallOutcome, )
Enqueue a hostcall completion.
Sourcepub fn enqueue_hostcall_completions<I>(&mut self, completions: I)
pub fn enqueue_hostcall_completions<I>(&mut self, completions: I)
Enqueue multiple hostcall completions in one scheduler mutation pass.
Sourcepub fn enqueue_stream_chunk(
&mut self,
call_id: String,
sequence: u64,
chunk: Value,
is_final: bool,
)
pub fn enqueue_stream_chunk( &mut self, call_id: String, sequence: u64, chunk: Value, is_final: bool, )
Convenience: enqueue a stream chunk for a hostcall.
Sourcepub fn enqueue_event(&mut self, event_id: String, payload: Value)
pub fn enqueue_event(&mut self, event_id: String, payload: Value)
Enqueue an inbound event from the host.
Sourcepub fn tick(&mut self) -> Option<Macrotask>
pub fn tick(&mut self) -> Option<Macrotask>
Execute one tick of the event loop.
Algorithm (from spec):
- Ingest host completions (done externally via enqueue methods)
- Move due timers to macrotask queue
- Run one macrotask (if any)
- Drain microtasks (done externally by JS engine)
Returns the macrotask that was executed, if any.
Sourcepub fn next_timer_deadline(&self) -> Option<u64>
pub fn next_timer_deadline(&self) -> Option<u64>
Get the deadline of the next timer, if any.
Sourcepub fn time_until_next_timer(&self) -> Option<u64>
pub fn time_until_next_timer(&self) -> Option<u64>
Get the time until the next timer fires, if any.
Trait Implementations§
Auto Trait Implementations§
impl<C> Freeze for Scheduler<C>where
C: Freeze,
impl<C> RefUnwindSafe for Scheduler<C>where
C: RefUnwindSafe,
impl<C> Send for Scheduler<C>
impl<C> Sync for Scheduler<C>
impl<C> Unpin for Scheduler<C>where
C: Unpin,
impl<C> UnsafeUnpin for Scheduler<C>where
C: UnsafeUnpin,
impl<C> UnwindSafe for Scheduler<C>where
C: UnwindSafe,
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().