From b7701a6f61b525c116e29981f122a58552751f78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Fri, 11 Jun 2021 18:40:05 +0200 Subject: AtomicBool::swap --- mumd/src/command.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'mumd') 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(); -- cgit v1.2.1