Remove unnecessary async-iness

This commit is contained in:
Joscha 2022-03-05 21:42:45 +01:00
parent b18b71f3d6
commit 4d204109f1
3 changed files with 16 additions and 18 deletions

View file

@ -368,8 +368,7 @@ impl CoveConnMt {
} }
} }
// TODO Make sync pub fn new(
pub async fn new(
url: String, url: String,
room: String, room: String,
timeout: Duration, timeout: Duration,

View file

@ -1,6 +1,7 @@
use std::sync::Arc; use std::sync::Arc;
use std::time::Duration; use std::time::Duration;
use tokio::runtime::Runtime;
use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender}; use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender};
use tokio::sync::oneshot::{self, Sender}; use tokio::sync::oneshot::{self, Sender};
use tokio::sync::{Mutex, MutexGuard}; use tokio::sync::{Mutex, MutexGuard};
@ -18,14 +19,13 @@ struct ConnConfig {
} }
impl ConnConfig { impl ConnConfig {
async fn new_conn(&self) -> (CoveConn, CoveConnMt) { fn new_conn(&self) -> (CoveConn, CoveConnMt) {
conn::new( conn::new(
self.url.clone(), self.url.clone(),
self.room.clone(), self.room.clone(),
self.timeout, self.timeout,
self.ev_tx.clone(), self.ev_tx.clone(),
) )
.await
} }
} }
@ -39,7 +39,9 @@ pub struct CoveRoom {
} }
impl CoveRoom { impl CoveRoom {
pub async fn new<E, F>( /// This method uses [`tokio::spawn`] and must thus be called in the context
/// of a tokio runtime.
pub fn new<E, F>(
config: &'static Config, config: &'static Config,
name: String, name: String,
event_sender: UnboundedSender<E>, event_sender: UnboundedSender<E>,
@ -58,7 +60,7 @@ impl CoveRoom {
room: name.clone(), room: name.clone(),
timeout: config.timeout, timeout: config.timeout,
}; };
let (conn, mt) = conf.new_conn().await; let (conn, mt) = conf.new_conn();
let room = Self { let room = Self {
name: name.clone(), name: name.clone(),
@ -122,7 +124,7 @@ impl CoveRoom {
url_exists = true; url_exists = true;
// TODO Clean up with restructuring assignments later? // 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; *conn.lock().await = new_conn;
mt = new_mt; mt = new_mt;
} }

View file

@ -182,7 +182,7 @@ impl Ui {
Some(OverlayReaction::Close) => self.overlay = None, Some(OverlayReaction::Close) => self.overlay = None,
Some(OverlayReaction::SwitchRoom(id)) => { Some(OverlayReaction::SwitchRoom(id)) => {
self.overlay = None; self.overlay = None;
self.switch_to_room(id).await; self.switch_to_room(id);
} }
None => {} None => {}
} }
@ -197,13 +197,11 @@ impl Ui {
event: KeyEvent, event: KeyEvent,
) -> Option<EventHandleResult> { ) -> Option<EventHandleResult> {
match &self.room { match &self.room {
Some(RoomId::Cove(name)) => { Some(RoomId::Cove(name)) => self
if let Some(ui) = self.cove_rooms.get_mut(name) { .cove_rooms
ui.handle_key(event).map(|_| EventHandleResult::Continue) .get_mut(name)
} else { .and_then(|ui| ui.handle_key(event))
None .and(Some(EventHandleResult::Continue)),
}
}
None => None, 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 { match &id {
RoomId::Cove(name) => { RoomId::Cove(name) => {
if let Entry::Vacant(entry) = self.cove_rooms.entry(name.clone()) { if let Entry::Vacant(entry) = self.cove_rooms.entry(name.clone()) {
@ -353,8 +351,7 @@ impl Ui {
name.clone(), name.clone(),
self.event_tx.clone(), self.event_tx.clone(),
UiEvent::cove, UiEvent::cove,
) );
.await;
entry.insert(CoveUi::new(room)); entry.insert(CoveUi::new(room));
} }
} }