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::ports::{EventBuffer, Output};
|
||||
use nexosim::simulation::{Mailbox, SimInit, SimulationError};
|
||||
use nexosim::simulation::{ExecutionError, Mailbox, SimInit, SimulationError};
|
||||
use nexosim::time::{AutoSystemClock, MonotonicTime};
|
||||
|
||||
const DELTA: Duration = Duration::from_millis(2);
|
||||
@ -123,5 +123,9 @@ fn main() -> Result<(), SimulationError> {
|
||||
|
||||
// Stop the simulation.
|
||||
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
|
||||
/// [`Simulation::step()`] repeatedly.
|
||||
///
|
||||
/// This method blocks until all events scheduled have completed. If
|
||||
/// simulation is halted, this method returns without an error.
|
||||
/// This method blocks until all events scheduled have completed.
|
||||
pub fn step_unbounded(&mut self) -> Result<(), ExecutionError> {
|
||||
match self.step_until_unchecked(None) {
|
||||
Err(ExecutionError::Halted) => Ok(()),
|
||||
result => result,
|
||||
}
|
||||
self.step_until_unchecked(None)
|
||||
}
|
||||
|
||||
/// Processes an action immediately, blocking until completion.
|
||||
|
Loading…
x
Reference in New Issue
Block a user