diff options
| author | Jokler <jokler@protonmail.com> | 2020-01-30 15:55:41 +0100 |
|---|---|---|
| committer | Jokler <jokler@protonmail.com> | 2020-02-22 23:20:10 +0100 |
| commit | 757edd214f841e8d95e4c5430d7ead7a0e8fecbb (patch) | |
| tree | 3d0721d1d1f73c9bc1fd5ac23aef505e1051d5e5 /src/teamspeak/mod.rs | |
| parent | 2792ba9c8a7120a91b3bd2c6075e737690e73405 (diff) | |
| download | pokebot-757edd214f841e8d95e4c5430d7ead7a0e8fecbb.tar.gz pokebot-757edd214f841e8d95e4c5430d7ead7a0e8fecbb.zip | |
Spawn actix-web server with access to the bot
Additionally replace all Mutexes with RwLocks.
Hopefully this makes it possible for the web server to
serve many requests at once since they would just hold read locks.
Diffstat (limited to 'src/teamspeak/mod.rs')
| -rw-r--r-- | src/teamspeak/mod.rs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/teamspeak/mod.rs b/src/teamspeak/mod.rs index 5ac0d44..7551e77 100644 --- a/src/teamspeak/mod.rs +++ b/src/teamspeak/mod.rs @@ -1,4 +1,4 @@ -use std::sync::{Arc, Mutex}; +use std::sync::{Arc, RwLock}; use std::time::{Duration, Instant}; use futures::compat::Future01CompatExt; @@ -76,7 +76,7 @@ fn get_message<'a>(event: &Event) -> Option<MusicBotMessage> { impl TeamSpeakConnection { pub async fn new( - tx: Arc<Mutex<UnboundedSender<MusicBotMessage>>>, + tx: Arc<RwLock<UnboundedSender<MusicBotMessage>>>, options: ConnectOptions, ) -> Result<TeamSpeakConnection, tsclientlib::Error> { let conn = Connection::new(options).compat().await?; @@ -89,7 +89,7 @@ impl TeamSpeakConnection { if let ConEvents(_conn, events) = e { for event in *events { if let Some(msg) = get_message(event) { - let tx = tx.lock().expect("Mutex was not poisoned"); + let tx = tx.read().expect("RwLock was not poisoned"); // Ignore the result because the receiver might get dropped first. let _ = tx.send(msg); } |
