aboutsummaryrefslogtreecommitdiffstats
path: root/mumd
diff options
context:
space:
mode:
Diffstat (limited to 'mumd')
-rw-r--r--mumd/src/command.rs4
1 files changed, 3 insertions, 1 deletions
diff --git a/mumd/src/command.rs b/mumd/src/command.rs
index 2a3f148..2069178 100644
--- a/mumd/src/command.rs
+++ b/mumd/src/command.rs
@@ -30,6 +30,7 @@ pub async fn handle(
);
match event {
ExecutionContext::TcpEventCallback(callbacks) => {
+ // A shared bool ensures that only one of the supplied callbacks is run.
let should_handle = Rc::new(AtomicBool::new(true));
for (event, generator) in callbacks {
let should_handle = Rc::clone(&should_handle);
@@ -37,7 +38,8 @@ pub async fn handle(
tcp_event_queue.register_callback(
event,
Box::new(move |e| {
- if should_handle.fetch_and(false, Ordering::Relaxed) {
+ // If should_handle == true no other callback has been run yet.
+ if should_handle.swap(false, Ordering::Relaxed) {
let response = generator(e);
for response in response {
response_sender.send(response).unwrap();