From 743d5f231c0f735410af91c40396b532a7ddf3d3 Mon Sep 17 00:00:00 2001 From: Jared Burce Date: Wed, 28 Oct 2020 18:05:21 -0700 Subject: [PATCH] Check if audio is busy in separate function --- src/main.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 197b7d0..44fae8f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -64,15 +64,10 @@ async fn main() { }), rx.filter_map(|()| async { - AUDIO_CHILD.with(|cell| { - if let Some(ref mut audio_child) = *cell.borrow_mut() { - if let Ok(None) = audio_child.try_wait() { - debug!("doorbell still ringing, ignoring press"); - return None; - } - } - Some(()) - })?; + if audio_busy() { + debug!("doorbell still ringing, ignoring press"); + return None; + } debug!("Playing doorbell chime"); match process::Command::new("mplayer") .arg("static/outdoor.mp3") @@ -92,3 +87,14 @@ async fn main() { let routes = root.or(events); warp::serve(routes).run(([0, 0, 0, 0], 8060)).await; } + +fn audio_busy() -> bool { + AUDIO_CHILD.with(|cell| { + if let Some(ref mut audio_child) = *cell.borrow_mut() { + if let Ok(None) = audio_child.try_wait() { + return true; + } + } + false + }) +}