pub struct TimeTrigger { /* private fields */ }Expand description
Trigger criterion for a specific simulation time.
TimeTrigger observes the simulation clock and emits when the simulation reaches a configured
time and execution phase.
§Construction
TimeTrigger::at(at)
TimeTrigger::at_phase(at, phase)
TimeTrigger::at(at).with_phase(phase)§Observation
The observation data passed to
TriggerCriterion::emit_with is TimeTriggerEvent. It
contains the simulation time observed when the scheduled plan runs and the phase used to schedule
it:
pub struct TimeTriggerEvent {
pub time: f64,
pub phase: ExecutionPhase,
}§Semantics
This trigger is equivalent to scheduling a plan that emits an event with
context.add_plan /
context.add_plan_with_phase.
TimeTrigger::at uses ExecutionPhase::Normal.
Constructor time inputs are converted to f64 and validated when the trigger is installed.
Since time is monotonic, this criterion does not use Direction or
TriggerMode. It emits once, when its scheduled plan executes. If several
plans are scheduled for the same time, the selected ExecutionPhase
controls phase ordering.
§Example
use ixa::{Context, ExecutionPhase, IxaEvent};
use ixa::triggers::{ContextTriggersExt, TimeTrigger, TriggerCriterion};
#[derive(IxaEvent)]
struct StopTimeReached {
time: f64,
phase: ExecutionPhase,
}
let mut context = Context::new();
context.register_trigger(
TimeTrigger::at_phase(50.0, ExecutionPhase::Last)
.emit_with(|observation| StopTimeReached {
time: observation.time,
phase: observation.phase,
}),
);
context.subscribe_to_event(|context, _event: StopTimeReached| {
context.shutdown();
});Implementations§
Source§impl TimeTrigger
impl TimeTrigger
pub fn at(at: impl Into<f64>) -> Self
pub fn at_phase(at: impl Into<f64>, phase: ExecutionPhase) -> Self
pub fn with_phase(self, phase: ExecutionPhase) -> Self
Trait Implementations§
Source§impl TriggerCriterion for TimeTrigger
impl TriggerCriterion for TimeTrigger
Source§type Observation = TimeTriggerEvent
type Observation = TimeTriggerEvent
Source§fn install<F>(self, context: &mut Context, on_match: F)
fn install<F>(self, context: &mut Context, on_match: F)
context.