Skip to content

Commit c356a4a

Browse files
committed
sim-lib: use sleep for timed shutdown instead of timeout
Allows us to keep the API for our clock a little simpler.
1 parent 45a19a2 commit c356a4a

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

simln-lib/src/lib.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -769,16 +769,23 @@ impl Simulation {
769769

770770
// Start a task that will shutdown the simulation if the total_time is met.
771771
if let Some(total_time) = self.cfg.total_time {
772-
let t = self.shutdown_trigger.clone();
773-
let l = self.shutdown_listener.clone();
772+
let shutdown = self.shutdown_trigger.clone();
773+
let listener = self.shutdown_listener.clone();
774774

775775
self.tasks.spawn(async move {
776-
if time::timeout(total_time, l).await.is_err() {
777-
log::info!(
778-
"Simulation run for {}s. Shutting down.",
779-
total_time.as_secs()
780-
);
781-
t.trigger()
776+
select! {
777+
biased;
778+
_ = listener.clone() => {
779+
log::debug!("Timeout task exited on listener signal");
780+
}
781+
782+
_ = time::sleep(total_time) => {
783+
log::info!(
784+
"Simulation run for {}s. Shutting down.",
785+
total_time.as_secs()
786+
);
787+
shutdown.trigger()
788+
}
782789
}
783790
});
784791
}

0 commit comments

Comments
 (0)