diff options
| author | Jokler <jokler@protonmail.com> | 2020-02-08 00:21:38 +0100 |
|---|---|---|
| committer | Jokler <jokler@protonmail.com> | 2020-02-08 00:29:40 +0100 |
| commit | cba088b9f32cc198aef83c2175d5c337a3da6aa9 (patch) | |
| tree | 8c6c9bf05abf251d41e27ef49718ebe4d082439e | |
| parent | 1d4c5bfd062d6ffb4b7f571c061cd58697d224e0 (diff) | |
| download | pokebot-cba088b9f32cc198aef83c2175d5c337a3da6aa9.tar.gz pokebot-cba088b9f32cc198aef83c2175d5c337a3da6aa9.zip | |
Name threads for better logging and debugging
| -rw-r--r-- | src/bot/music.rs | 64 |
1 files changed, 35 insertions, 29 deletions
diff --git a/src/bot/music.rs b/src/bot/music.rs index dee1514..4de4d4b 100644 --- a/src/bot/music.rs +++ b/src/bot/music.rs @@ -369,40 +369,46 @@ impl MusicBot { fn spawn_stdin_reader(tx: Arc<Mutex<UnboundedSender<MusicBotMessage>>>) { debug!("Spawning stdin reader thread"); - thread::spawn(move || { - let stdin = ::std::io::stdin(); - let lock = stdin.lock(); - for line in lock.lines() { - let line = line.unwrap(); - - let message = MusicBotMessage::TextMessage(Message { - target: MessageTarget::Channel, - invoker: Invoker { - name: String::from("stdin"), - id: ClientId(0), - uid: None, - }, - text: line, - }); - - let tx = tx.lock().unwrap(); - tx.send(message).unwrap(); - } - }); + thread::Builder::new() + .name(String::from("stdin reader")) + .spawn(move || { + let stdin = ::std::io::stdin(); + let lock = stdin.lock(); + for line in lock.lines() { + let line = line.unwrap(); + + let message = MusicBotMessage::TextMessage(Message { + target: MessageTarget::Channel, + invoker: Invoker { + name: String::from("stdin"), + id: ClientId(0), + uid: None, + }, + text: line, + }); + + let tx = tx.lock().unwrap(); + tx.send(message).unwrap(); + } + }) + .expect("Failed to spawn stdin reader thread"); } fn spawn_gstreamer_thread( player: Arc<AudioPlayer>, tx: Arc<Mutex<UnboundedSender<MusicBotMessage>>>, ) { - thread::spawn(move || loop { - if player.poll() == PollResult::Quit { - break; - } + thread::Builder::new() + .name(String::from("gstreamer polling")) + .spawn(move || loop { + if player.poll() == PollResult::Quit { + break; + } - tx.lock() - .unwrap() - .send(MusicBotMessage::StateChange(State::EndOfStream)) - .unwrap(); - }); + tx.lock() + .unwrap() + .send(MusicBotMessage::StateChange(State::EndOfStream)) + .unwrap(); + }) + .expect("Failed to spawn gstreamer thread"); } |
