pub struct Scheduler(/* private fields */);Expand description
A scheduler for events and queries meant to be processed at specified deadlines.
The Scheduler handle is Clone-able and can be shared or sent to other
threads.
When scheduling an event or query, it is important to consider that its
deadline must be in the future of the current simulation time and that
stepping method such as
Simulation::step or
Simulation::run eagerly advance the
simulation time to the deadline of the next scheduled event or simulation
tick. If a stepping method is executed concurrently, therefore, events or
queries can only be scheduled after the deadline associated with the next
scheduler event or simulation tick.
Implementations§
Source§impl Scheduler
impl Scheduler
Sourcepub fn time(&self) -> MonotonicTime
pub fn time(&self) -> MonotonicTime
Returns the current simulation time.
§Examples
use nexosim::simulation::Scheduler;
use nexosim::time::MonotonicTime;
fn is_third_millennium(scheduler: &Scheduler) -> bool {
let time = scheduler.time();
time >= MonotonicTime::new(978307200, 0).unwrap()
&& time < MonotonicTime::new(32535216000, 0).unwrap()
}Sourcepub fn schedule_event<T>(
&self,
deadline: impl Deadline,
event_id: &EventId<T>,
arg: T,
) -> Result<(), SchedulingError>
pub fn schedule_event<T>( &self, deadline: impl Deadline, event_id: &EventId<T>, arg: T, ) -> Result<(), SchedulingError>
Schedules an event at a future time.
An error is returned if the specified time is not in the future of the current simulation time.
Events scheduled for the same time and targeting the same model are guaranteed to be processed according to the scheduling order.
Sourcepub fn schedule_keyed_event<T>(
&self,
deadline: impl Deadline,
event_id: &EventId<T>,
arg: T,
) -> Result<EventKey, SchedulingError>
pub fn schedule_keyed_event<T>( &self, deadline: impl Deadline, event_id: &EventId<T>, arg: T, ) -> Result<EventKey, SchedulingError>
Schedules a cancellable event at a future time and returns an event key.
An error is returned if the specified time is not in the future of the current simulation time.
Events scheduled for the same time and targeting the same model are guaranteed to be processed according to the scheduling order.
Sourcepub fn schedule_periodic_event<T>(
&self,
deadline: impl Deadline,
period: Duration,
event_id: &EventId<T>,
arg: T,
) -> Result<(), SchedulingError>
pub fn schedule_periodic_event<T>( &self, deadline: impl Deadline, period: Duration, event_id: &EventId<T>, arg: T, ) -> Result<(), SchedulingError>
Schedules a periodically recurring event at a future time.
An error is returned if the specified time is not in the future of the current simulation time, or if the specified period is null.
Events scheduled for the same time and targeting the same model are guaranteed to be processed according to the scheduling order.
Sourcepub fn schedule_keyed_periodic_event<T>(
&self,
deadline: impl Deadline,
period: Duration,
event_id: &EventId<T>,
arg: T,
) -> Result<EventKey, SchedulingError>
pub fn schedule_keyed_periodic_event<T>( &self, deadline: impl Deadline, period: Duration, event_id: &EventId<T>, arg: T, ) -> Result<EventKey, SchedulingError>
Schedules a cancellable, periodically recurring event at a future time and returns an event key.
An error is returned if the specified time is not in the future of the current simulation time, or if the specified period is null.
Events scheduled for the same time and targeting the same model are guaranteed to be processed according to the scheduling order.
Sourcepub fn schedule_query<T, R>(
&self,
deadline: impl Deadline,
query_id: &QueryId<T, R>,
arg: T,
) -> Result<ReplyReader<R>, SchedulingError>
pub fn schedule_query<T, R>( &self, deadline: impl Deadline, query_id: &QueryId<T, R>, arg: T, ) -> Result<ReplyReader<R>, SchedulingError>
Schedules a query at a future time.
An error is returned if the specified time is not in the future of the current simulation.
Queries scheduled for the same time and targeting the same model are guaranteed to be processed according to the scheduling order.
Sourcepub fn halt(&self)
pub fn halt(&self)
Requests the simulation to be interrupted at the earliest opportunity.
If a stepping method such as
Simulation::step or
Simulation::run is concurrently
being executed, this will cause such method to return before it steps to
next scheduler deadline or simulation tick (if any) with
ExecutionError::Halted.
Otherwise, this will cause the next call to a Simulation::step* or
Simulation::process* method to return immediately with
ExecutionError::Halted.
In all cases, once
ExecutionError::Halted is
returned, the simulation can be resumed at any moment with another call
to a stepping method or a
Simulation::process_*
methods.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Scheduler
impl RefUnwindSafe for Scheduler
impl Send for Scheduler
impl Sync for Scheduler
impl Unpin for Scheduler
impl UnwindSafe for Scheduler
Blanket Implementations§
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request