diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-06-11 18:40:05 +0200 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-06-11 18:40:05 +0200 |
| commit | b7701a6f61b525c116e29981f122a58552751f78 (patch) | |
| tree | 859b413c34f983eed819e86db1f9ec0228e3b4b6 | |
| parent | 24ab81363b18f874c68690ae54ba8a27bd46acd3 (diff) | |
| download | mum-b7701a6f61b525c116e29981f122a58552751f78.tar.gz | |
AtomicBool::swap
| -rw-r--r-- | mumd/src/command.rs | 4 |
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(); |
