From 45df95704da5b3c8767f6511bfde6505f7fd9fbf Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Tue, 8 Dec 2020 17:07:36 -0600 Subject: [PATCH] chore: assign name to audio thread --- src/alert.rs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/alert.rs b/src/alert.rs index fe01896..0f355e9 100644 --- a/src/alert.rs +++ b/src/alert.rs @@ -2,6 +2,7 @@ use rodio::{Decoder, OutputStream, Sink}; use std::fs::File; use std::io::BufReader; use std::path::PathBuf; +use std::thread; #[derive(Debug, Clone)] pub struct Alert { @@ -20,20 +21,21 @@ impl Alert { pub fn play(&self) { let file = File::open(&self.path).unwrap(); - std::thread::spawn(move || { - let (_stream, handle) = OutputStream::try_default().unwrap(); - let source = Decoder::new(BufReader::new(file)).unwrap(); - let sink = Sink::try_new(&handle).unwrap(); + thread::Builder::new() + .name("Audio Thread".to_string()) + .spawn(move || { + let (_stream, handle) = OutputStream::try_default().unwrap(); + let source = Decoder::new(BufReader::new(file)).unwrap(); + let sink = Sink::try_new(&handle).unwrap(); - sink.append(source); + sink.append(source); - loop { - if sink.len() == 0 { - break; + loop { + if sink.len() == 0 { + break; + } } - } - - println!("Exited Playback Thread."); - }); + }) + .unwrap(); } }