diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-06-07 23:02:30 +0200 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-06-07 23:02:30 +0200 |
| commit | 7072e0fdc79fca1f8de07032dab163ef2a2d0e64 (patch) | |
| tree | b29e3fbb868b30ada41395fba3e71de17d246355 /mumd/src/command.rs | |
| parent | 8744d7bff9941302dba05ddbfa98d50a255fc8d5 (diff) | |
| download | mum-7072e0fdc79fca1f8de07032dab163ef2a2d0e64.tar.gz | |
only call one callback per event callback registration
Diffstat (limited to 'mumd/src/command.rs')
| -rw-r--r-- | mumd/src/command.rs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/mumd/src/command.rs b/mumd/src/command.rs index 73ab3bd..2a3f148 100644 --- a/mumd/src/command.rs +++ b/mumd/src/command.rs @@ -4,10 +4,7 @@ use crate::state::{ExecutionContext, State}; use log::*; use mumble_protocol::{control::ControlPacket, Serverbound}; use mumlib::command::{Command, CommandResponse}; -use std::sync::{ - atomic::{AtomicU64, Ordering}, - Arc, RwLock, -}; +use std::{rc::Rc, sync::{Arc, RwLock, atomic::{AtomicBool, AtomicU64, Ordering}}}; use tokio::sync::{mpsc, watch}; pub async fn handle( @@ -33,14 +30,18 @@ pub async fn handle( ); match event { ExecutionContext::TcpEventCallback(callbacks) => { + let should_handle = Rc::new(AtomicBool::new(true)); for (event, generator) in callbacks { + let should_handle = Rc::clone(&should_handle); let response_sender = response_sender.clone(); tcp_event_queue.register_callback( event, Box::new(move |e| { - let response = generator(e); - for response in response { - response_sender.send(response).unwrap(); + if should_handle.fetch_and(false, Ordering::Relaxed) { + let response = generator(e); + for response in response { + response_sender.send(response).unwrap(); + } } }), ); |
