use werewolves_proto::error::GameError; use crate::{ communication::{host::HostComms, player::PlayerIdComms}, runner::Message, }; pub mod host; pub mod lobby; pub mod player; pub struct Comms { host: HostComms, player: PlayerIdComms, } impl Comms { pub const fn new(host: HostComms, player: PlayerIdComms) -> Self { Self { host, player } } pub const fn host(&mut self) -> &mut HostComms { &mut self.host } #[allow(unused)] pub const fn player(&mut self) -> &mut PlayerIdComms { &mut self.player } pub async fn message(&mut self) -> Result { tokio::select! { msg = self.host.recv() => { match msg { Some(msg) => Ok(Message::Host(msg)), None => Err(GameError::HostChannelClosed), } } Ok(msg) = self.player.recv() => { Ok(Message::Client(msg)) } } } }