mirror of
				https://github.com/csehviktor/status-monitor.git
				synced 2025-08-08 18:06:14 +02:00 
			
		
		
		
	cleaup code
This commit is contained in:
		
							
								
								
									
										26
									
								
								server/src/bridge.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								server/src/bridge.rs
									
									
									
									
									
										Normal 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() | ||||
|         }); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user