feat: use TxSendMessage

This commit is contained in:
2021-05-17 23:31:13 +08:00
parent f57ffdf646
commit 05693babdd
3 changed files with 36 additions and 27 deletions

View File

@@ -7,3 +7,18 @@ use std::sync::{Mutex, Arc};
pub type Tx = UnboundedSender<Message>;
pub type PeerMap = Arc<Mutex<HashMap<SocketAddr, Tx>>>;
pub type RoomMap = Arc<Mutex<BTreeMap<String, BTreeMap<String, SocketAddr>>>>;
pub trait TxSendMessage {
fn send_close(&self) -> bool;
fn send_text<S>(&self, text: S) -> bool where S: Into<String>;
}
impl TxSendMessage for Tx {
fn send_close(&self) -> bool {
self.unbounded_send(Message::Close(None)).is_ok()
}
fn send_text<S>(&self, text: S) -> bool where S: Into<String> {
self.unbounded_send(Message::Text(text.into())).is_ok()
}
}