Function wait_event

Source
pub fn wait_event<T: Bag>(
    t_start: f64,
    time_scale: f64,
    max_jitter: Option<Duration>,
    input_handler: impl FnMut(Duration, &mut T),
) -> impl FnMut(f64, &mut T) -> f64
Expand description

It computes the next wall-clock time corresponding to the next state transition of the model.

An input handler function waits for external events without exceeding the time for the next internal event. Finally, it checks that the wall-clock drift does not exceed the maximum jitter allowed (if any) and panics if it does.

§Arguments

  • t_start - The virtual time at the beginning of the simulation.
  • time_scale - The time scale factor between virtual and wall-clock time.
  • max_jitter - The maximum allowed jitter duration. If None, no jitter check is performed.
  • input_handler - The function to handle incoming external events. This function expects two arguments:
    • duration: [Duration] - Maximum duration of the time interval to wait for external events. The input handler function may return earlier if an input event is received. Note, however, that it must NOT return after, as it would result in an incorrect real-time implementation.
    • input_ports: &mut T - Mutable reference to the input ports of the top-most model under simulation.

§Returns

A closure that takes the next virtual time and a mutable reference to the bag and returns the next virtual time.

§Example

xdevs::simulator::std::wait_event(0., 1., Some(Duration::from_millis(50)), some_input_handler);