From 6e7d6213aa8ab81cf917e1234e71f33b061427ff Mon Sep 17 00:00:00 2001 From: tali Date: Sun, 16 Apr 2023 19:48:39 -0400 Subject: [PATCH] fix bug with handling early exits by breaking out of the correct loop --- tidepool/src/main.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tidepool/src/main.rs b/tidepool/src/main.rs index 30e320a..7871063 100644 --- a/tidepool/src/main.rs +++ b/tidepool/src/main.rs @@ -350,9 +350,9 @@ fn run_simulation( let time_start = Instant::now(); - while sim.lines_left() > 0 { + 'playing: while sim.lines_left() > 0 { if exit_early.load(atomic::Ordering::Relaxed) { - break; + break 'playing; } // initialize the bot for the current state @@ -373,8 +373,11 @@ fn run_simulation( bot.think_for(gas); // send a heartbeat back to the main thread to test if its still alive - if exit_early.load(atomic::Ordering::Relaxed) || tx.send(Msg::Heartbeat(id)).is_err() { - break; + if tx.send(Msg::Heartbeat(id)).is_err() { + break 'playing; + } + if exit_early.load(atomic::Ordering::Relaxed) { + break 'playing; } } @@ -382,7 +385,7 @@ fn run_simulation( // this should never fail unless something went wrong e.g. not enough iters, // impossible board state, or buggy bot tracing::warn!("gave up :( pieces={}, id={id}", sim.pieces()); - break; + break 'playing; }; sim.play(placement); @@ -399,7 +402,7 @@ fn run_simulation( time: Instant::now() - time_start, }; if tx.send(Msg::Status(id, status.into())).is_err() { - break; + break 'playing; } }