1
0
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:
Jauhien Piatlicki 2025-01-17 12:59:31 +01:00 committed by GitHub
commit 81c1d61290
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 8 deletions

View File

@ -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(()),
}
} }

View File

@ -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.