From 2e58288b04242b69b02d0854fe0173915a149c55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ja=C5=ADhien=20Piatlicki?= Date: Fri, 17 Jan 2025 12:13:47 +0100 Subject: [PATCH 1/2] Make step_unbounded return an error when halted. --- nexosim/examples/infinite_loop.rs | 8 ++++++-- nexosim/src/simulation.rs | 8 ++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/nexosim/examples/infinite_loop.rs b/nexosim/examples/infinite_loop.rs index 32c92b5..4611ddd 100644 --- a/nexosim/examples/infinite_loop.rs +++ b/nexosim/examples/infinite_loop.rs @@ -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()?) + Ok(match simulation_handle.join().unwrap() { + Err(ExecutionError::Halted) => Ok(()), + Err(e) => Err(e), + _ => Ok(()), + }?) } diff --git a/nexosim/src/simulation.rs b/nexosim/src/simulation.rs index cae82bf..70e159d 100644 --- a/nexosim/src/simulation.rs +++ b/nexosim/src/simulation.rs @@ -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. From fea1ccc1c421a4297f9c7a312c0ff20f787e4c03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ja=C5=ADhien=20Piatlicki?= Date: Fri, 17 Jan 2025 12:18:18 +0100 Subject: [PATCH 2/2] Changes after review. --- nexosim/examples/infinite_loop.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nexosim/examples/infinite_loop.rs b/nexosim/examples/infinite_loop.rs index 4611ddd..5ca7408 100644 --- a/nexosim/examples/infinite_loop.rs +++ b/nexosim/examples/infinite_loop.rs @@ -123,9 +123,9 @@ fn main() -> Result<(), SimulationError> { // Stop the simulation. scheduler.halt(); - Ok(match simulation_handle.join().unwrap() { + match simulation_handle.join().unwrap() { Err(ExecutionError::Halted) => Ok(()), - Err(e) => Err(e), + Err(e) => Err(e.into()), _ => Ok(()), - }?) + } }