From cba088b9f32cc198aef83c2175d5c337a3da6aa9 Mon Sep 17 00:00:00 2001 From: Jokler Date: Sat, 8 Feb 2020 00:21:38 +0100 Subject: Name threads for better logging and debugging --- src/bot/music.rs | 64 +++++++++++++++++++++++++++++++------------------------- 1 file 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>>) { 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, tx: Arc>>, ) { - 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"); } -- cgit v1.2.3-70-g09d2