diff --git a/cove-tui/src/client/cove/conn.rs b/cove-tui/src/client/cove/conn.rs index 5743dfe..e27c2c3 100644 --- a/cove-tui/src/client/cove/conn.rs +++ b/cove-tui/src/client/cove/conn.rs @@ -368,8 +368,7 @@ impl CoveConnMt { } } -// TODO Make sync -pub async fn new( +pub fn new( url: String, room: String, timeout: Duration, diff --git a/cove-tui/src/client/cove/room.rs b/cove-tui/src/client/cove/room.rs index 2016b37..236dbf3 100644 --- a/cove-tui/src/client/cove/room.rs +++ b/cove-tui/src/client/cove/room.rs @@ -1,6 +1,7 @@ use std::sync::Arc; use std::time::Duration; +use tokio::runtime::Runtime; use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender}; use tokio::sync::oneshot::{self, Sender}; use tokio::sync::{Mutex, MutexGuard}; @@ -18,14 +19,13 @@ struct ConnConfig { } impl ConnConfig { - async fn new_conn(&self) -> (CoveConn, CoveConnMt) { + fn new_conn(&self) -> (CoveConn, CoveConnMt) { conn::new( self.url.clone(), self.room.clone(), self.timeout, self.ev_tx.clone(), ) - .await } } @@ -39,7 +39,9 @@ pub struct CoveRoom { } impl CoveRoom { - pub async fn new( + /// This method uses [`tokio::spawn`] and must thus be called in the context + /// of a tokio runtime. + pub fn new( config: &'static Config, name: String, event_sender: UnboundedSender, @@ -58,7 +60,7 @@ impl CoveRoom { room: name.clone(), timeout: config.timeout, }; - let (conn, mt) = conf.new_conn().await; + let (conn, mt) = conf.new_conn(); let room = Self { name: name.clone(), @@ -122,7 +124,7 @@ impl CoveRoom { url_exists = true; // TODO Clean up with restructuring assignments later? - let (new_conn, new_mt) = conf.new_conn().await; + let (new_conn, new_mt) = conf.new_conn(); *conn.lock().await = new_conn; mt = new_mt; } diff --git a/cove-tui/src/ui.rs b/cove-tui/src/ui.rs index 605aa9e..7a2d79f 100644 --- a/cove-tui/src/ui.rs +++ b/cove-tui/src/ui.rs @@ -182,7 +182,7 @@ impl Ui { Some(OverlayReaction::Close) => self.overlay = None, Some(OverlayReaction::SwitchRoom(id)) => { self.overlay = None; - self.switch_to_room(id).await; + self.switch_to_room(id); } None => {} } @@ -197,13 +197,11 @@ impl Ui { event: KeyEvent, ) -> Option { match &self.room { - Some(RoomId::Cove(name)) => { - if let Some(ui) = self.cove_rooms.get_mut(name) { - ui.handle_key(event).map(|_| EventHandleResult::Continue) - } else { - None - } - } + Some(RoomId::Cove(name)) => self + .cove_rooms + .get_mut(name) + .and_then(|ui| ui.handle_key(event)) + .and(Some(EventHandleResult::Continue)), None => None, } } @@ -344,7 +342,7 @@ impl Ui { } } - async fn switch_to_room(&mut self, id: RoomId) { + fn switch_to_room(&mut self, id: RoomId) { match &id { RoomId::Cove(name) => { if let Entry::Vacant(entry) = self.cove_rooms.entry(name.clone()) { @@ -353,8 +351,7 @@ impl Ui { name.clone(), self.event_tx.clone(), UiEvent::cove, - ) - .await; + ); entry.insert(CoveUi::new(room)); } }