forked from ROMEO/nexosim
Merge pull request #77 from asynchronics/feature-simulation-halt
Make step_unbounded return an error when halted.
This commit is contained in:
commit
81c1d61290
@ -26,7 +26,7 @@ use std::time::Duration;
|
|||||||
|
|
||||||
use nexosim::model::{Context, InitializedModel, Model};
|
use nexosim::model::{Context, InitializedModel, Model};
|
||||||
use nexosim::ports::{EventBuffer, Output};
|
use nexosim::ports::{EventBuffer, Output};
|
||||||
use nexosim::simulation::{Mailbox, SimInit, SimulationError};
|
use nexosim::simulation::{ExecutionError, Mailbox, SimInit, SimulationError};
|
||||||
use nexosim::time::{AutoSystemClock, MonotonicTime};
|
use nexosim::time::{AutoSystemClock, MonotonicTime};
|
||||||
|
|
||||||
const DELTA: Duration = Duration::from_millis(2);
|
const DELTA: Duration = Duration::from_millis(2);
|
||||||
@ -123,5 +123,9 @@ fn main() -> Result<(), SimulationError> {
|
|||||||
|
|
||||||
// Stop the simulation.
|
// Stop the simulation.
|
||||||
scheduler.halt();
|
scheduler.halt();
|
||||||
Ok(simulation_handle.join().unwrap()?)
|
match simulation_handle.join().unwrap() {
|
||||||
|
Err(ExecutionError::Halted) => Ok(()),
|
||||||
|
Err(e) => Err(e.into()),
|
||||||
|
_ => Ok(()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -242,13 +242,9 @@ impl Simulation {
|
|||||||
/// Iteratively advances the simulation time, as if by calling
|
/// Iteratively advances the simulation time, as if by calling
|
||||||
/// [`Simulation::step()`] repeatedly.
|
/// [`Simulation::step()`] repeatedly.
|
||||||
///
|
///
|
||||||
/// This method blocks until all events scheduled have completed. If
|
/// This method blocks until all events scheduled have completed.
|
||||||
/// simulation is halted, this method returns without an error.
|
|
||||||
pub fn step_unbounded(&mut self) -> Result<(), ExecutionError> {
|
pub fn step_unbounded(&mut self) -> Result<(), ExecutionError> {
|
||||||
match self.step_until_unchecked(None) {
|
self.step_until_unchecked(None)
|
||||||
Err(ExecutionError::Halted) => Ok(()),
|
|
||||||
result => result,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Processes an action immediately, blocking until completion.
|
/// Processes an action immediately, blocking until completion.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user