Skip to content

Commit 3153add

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 c103f94 commit 3153add

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
@@ -699,16 +699,23 @@ impl Simulation {
699699

700700
// Start a task that will shutdown the simulation if the total_time is met.
701701
if let Some(total_time) = self.cfg.total_time {
702-
let t = self.shutdown_trigger.clone();
703-
let l = self.shutdown_listener.clone();
702+
let shutdown = self.shutdown_trigger.clone();
703+
let listener = self.shutdown_listener.clone();
704704

705705
self.tasks.spawn(async move {
706-
if time::timeout(total_time, l).await.is_err() {
707-
log::info!(
708-
"Simulation run for {}s. Shutting down.",
709-
total_time.as_secs()
710-
);
711-
t.trigger()
706+
select! {
707+
biased;
708+
_ = listener.clone() => {
709+
log::debug!("Timeout task exited on listener signal");
710+
}
711+
712+
_ = time::sleep(total_time) => {
713+
log::info!(
714+
"Simulation run for {}s. Shutting down.",
715+
total_time.as_secs()
716+
);
717+
shutdown.trigger()
718+
}
712719
}
713720
});
714721
}

0 commit comments

Comments
 (0)