From c4f78f2dadf5de918a40dfd825940fadaf009b47 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Wed, 28 Sep 2022 07:12:36 +0200 Subject: implement into_join_handle for RemoteBotHandle --- planetwars-server/src/modules/client_api.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'planetwars-server/src/modules') diff --git a/planetwars-server/src/modules/client_api.rs b/planetwars-server/src/modules/client_api.rs index ddba3cb..6e5d05a 100644 --- a/planetwars-server/src/modules/client_api.rs +++ b/planetwars-server/src/modules/client_api.rs @@ -13,6 +13,7 @@ use std::time::Duration; use runner::match_context::{EventBus, PlayerHandle, RequestError, RequestMessage}; use runner::match_log::MatchLogger; use tokio::sync::{mpsc, oneshot}; +use tokio::task::JoinHandle; use tokio_stream::wrappers::UnboundedReceiverStream; use tonic; use tonic::transport::Server; @@ -252,13 +253,18 @@ impl runner::BotSpec for RemoteBotSpec { let client_messages_future = tokio::time::timeout(Duration::from_secs(10), client_messages_promise.get_value()); - if let Ok(Ok(client_messages)) = client_messages_future.await { + let join_handle = if let Ok(Ok(client_messages)) = client_messages_future.await { tokio::spawn(handle_bot_messages( player_id, event_bus.clone(), client_messages, - )); - } + )) + } else { + // since we don't have a mechanism for bot failure yet, + // this hack will have to do for now. + // TODO: FIXME + tokio::spawn(futures::future::ready(())) + }; // ensure router cleanup self.router.take(&self.player_key); @@ -271,6 +277,7 @@ impl runner::BotSpec for RemoteBotSpec { sender: server_msg_snd, player_id, event_bus, + join_handle, }) } } @@ -299,6 +306,7 @@ struct RemoteBotHandle { sender: mpsc::UnboundedSender>, player_id: u32, event_bus: Arc>, + join_handle: JoinHandle<()>, } impl PlayerHandle for RemoteBotHandle { @@ -335,6 +343,10 @@ impl PlayerHandle for RemoteBotHandle { } } } + + fn into_join_handle(self: Box) -> JoinHandle<()> { + self.join_handle + } } // TODO: this will spawn a task for every request, which might not be ideal. -- cgit v1.2.3