From f7fe187c464525339c58996ec86b4faea4306789 Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Tue, 4 Jun 2024 20:59:56 +0200 Subject: Use unbounded mpsc channel --- src/audio/mod.rs | 2 +- src/audio/mpv.rs | 2 +- src/audio/rodio.rs | 4 ++-- src/main.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/audio/mod.rs b/src/audio/mod.rs index 81cdc70..6d2dda3 100644 --- a/src/audio/mod.rs +++ b/src/audio/mod.rs @@ -15,7 +15,7 @@ pub fn get_backend() -> AudioBackends { } impl AudioBackends { - pub async fn play(&self, url: &str, tx: mpsc::Sender) { + pub async fn play(&self, url: &str, tx: mpsc::UnboundedSender) { match self { AudioBackends::Mpv(m) => m.play(url, tx).await, AudioBackends::Rodio(r) => r.play(url, tx).await, diff --git a/src/audio/mpv.rs b/src/audio/mpv.rs index 06d3630..a9b3bc1 100644 --- a/src/audio/mpv.rs +++ b/src/audio/mpv.rs @@ -4,7 +4,7 @@ use tokio::sync::mpsc; pub struct Mpv {} impl Mpv { - pub async fn play(&self, url: &str, _tx: mpsc::Sender) { + pub async fn play(&self, url: &str, _tx: mpsc::UnboundedSender) { Command::new("mpv") .args([url]) .output() diff --git a/src/audio/rodio.rs b/src/audio/rodio.rs index 695c6cb..f5ad5cc 100644 --- a/src/audio/rodio.rs +++ b/src/audio/rodio.rs @@ -13,7 +13,7 @@ const AUDIO_BUFFER_SECONDS: u32 = 5; pub struct Rodio {} impl Rodio { - pub async fn play(&self, url: &str, tx: mpsc::Sender) { + pub async fn play(&self, url: &str, tx: mpsc::UnboundedSender) { let (_stream, handle) = OutputStream::try_default().unwrap(); let sink = Sink::try_new(&handle).unwrap(); @@ -57,7 +57,7 @@ impl Rodio { } }, )) - .unwrap(), + .expect("Failed to play stream, check network and try again later"), ); let handle = tokio::task::spawn_blocking(move || { diff --git a/src/main.rs b/src/main.rs index 19442a6..4cee4d1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,7 @@ async fn main() { let ans: Result = Select::new("Select channel from list:", channels).prompt(); - let (tx, mut rx) = mpsc::channel(5); + let (tx, mut rx) = mpsc::unbounded_channel(); match ans { Ok(ch) => { -- cgit v1.3.1