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 + }) +}