Skip to content

Commit

Permalink
fix: race condition in use of of atomic variable (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
c-git authored Mar 7, 2024
1 parent 2cd2ee9 commit 9def484
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions examples/event_handler/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ async fn event_handler(
}
serenity::FullEvent::Message { new_message } => {
if new_message.content.to_lowercase().contains("poise") {
let mentions = data.poise_mentions.load(Ordering::SeqCst) + 1;
data.poise_mentions.store(mentions, Ordering::SeqCst);
let old_mentions = data.poise_mentions.fetch_add(1, Ordering::SeqCst);
new_message
.reply(ctx, format!("Poise has been mentioned {} times", mentions))
.reply(
ctx,
format!("Poise has been mentioned {} times", old_mentions + 1),
)
.await?;
}
}
Expand Down

0 comments on commit 9def484

Please sign in to comment.