mirror of
https://github.com/csehviktor/status-monitor.git
synced 2026-04-29 00:27:35 +02:00
cleaup code
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
use tokio::sync::{mpsc::Sender, Mutex};
|
||||
|
||||
pub struct ClientManager {
|
||||
clients: Mutex<Vec<Sender<String>>>,
|
||||
}
|
||||
|
||||
impl ClientManager {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
clients: Mutex::new(Vec::new()),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn add_client(&self, client: Sender<String>) {
|
||||
let mut clients = self.clients.lock().await;
|
||||
clients.push(client);
|
||||
}
|
||||
|
||||
pub async fn broadcast(&self, message: String) {
|
||||
let mut clients = self.clients.lock().await;
|
||||
|
||||
clients.retain(|client| {
|
||||
client.try_send(message.clone()).is_ok()
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user