cleaup code

This commit is contained in:
csehviktor
2025-07-05 15:55:57 +02:00
parent 3bcfc67bdb
commit 81719e5574
14 changed files with 224 additions and 121 deletions

26
server/src/bridge.rs Normal file
View File

@@ -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()
});
}
}