aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Kaaman <tmtu@tmtu.ee>2020-02-08 01:18:10 +0100
committerGitHub <noreply@github.com>2020-02-08 01:18:10 +0100
commit96ea75ebce848e5c5354956315fb4ba9fd6bffed (patch)
tree8c6c9bf05abf251d41e27ef49718ebe4d082439e
parent1d4c5bfd062d6ffb4b7f571c061cd58697d224e0 (diff)
parentcba088b9f32cc198aef83c2175d5c337a3da6aa9 (diff)
downloadpokebot-96ea75ebce848e5c5354956315fb4ba9fd6bffed.tar.gz
pokebot-96ea75ebce848e5c5354956315fb4ba9fd6bffed.zip
Merge pull request #30 from Mavulp/name-threads
Name threads for better logging and debugging
-rw-r--r--src/bot/music.rs64
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");
}