diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-09-23 21:34:57 +0200 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-09-23 21:34:57 +0200 |
commit | a1d81ac774c0ae52f155cd764fd74fd1ba928a5f (patch) | |
tree | f0d4c7fda3f09fcc824795100b045d456baeecec /planetwars-matchrunner/src/match_context.rs | |
parent | 8f3621813e44df2dace49a6400cfe870bc3778ea (diff) | |
download | planetwars.dev-a1d81ac774c0ae52f155cd764fd74fd1ba928a5f.tar.xz planetwars.dev-a1d81ac774c0ae52f155cd764fd74fd1ba928a5f.zip |
ensure bots cleanly stop before a match completes
Diffstat (limited to 'planetwars-matchrunner/src/match_context.rs')
-rw-r--r-- | planetwars-matchrunner/src/match_context.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/planetwars-matchrunner/src/match_context.rs b/planetwars-matchrunner/src/match_context.rs index 859b11d..bdc87a3 100644 --- a/planetwars-matchrunner/src/match_context.rs +++ b/planetwars-matchrunner/src/match_context.rs @@ -7,6 +7,7 @@ use std::{ collections::HashMap, sync::{Arc, Mutex}, }; +use tokio::task::JoinHandle; use crate::match_log::{MatchLogMessage, MatchLogger}; @@ -71,10 +72,19 @@ impl MatchCtx { pub fn log(&mut self, message: MatchLogMessage) { self.match_logger.send(message).expect("write failed"); } + + pub async fn shutdown(self) { + let join_handles = self + .players + .into_iter() + .map(|(_player_id, player_data)| player_data.handle.into_join_handle()); + futures::future::join_all(join_handles).await; + } } pub trait PlayerHandle: Send { fn send_request(&mut self, r: RequestMessage); + fn into_join_handle(self: Box<Self>) -> JoinHandle<()>; } struct PlayerData { |