From 93bf955a3714ae0173acac0ff90419d4ec37ffb3 Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Thu, 19 Oct 2023 09:41:10 +0700 Subject: [PATCH] Rework how the wakecommand works --- src/mqtt/mod.rs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/mqtt/mod.rs b/src/mqtt/mod.rs index 029059a..5408446 100644 --- a/src/mqtt/mod.rs +++ b/src/mqtt/mod.rs @@ -969,22 +969,15 @@ async fn handle_mqtt_message( let reply = match message.parse::() { Ok(secs) => { if let Ok(permit) = camera.permit().await { - let (tx, mut rx) = mpsc(1); - - // By using a run_task we can delay the countdown until AFTER we are connected - let _ = camera.run_task(|_cam| { - let tx = tx.clone(); - Box::pin(async move { - let _ = tx.try_send(()); // Camera online, start the countdown - AnyResult::Ok(()) - }) - }); - // This task waits for the `run_task` to send the OK then starts the countdown // to drop the permit + let camera = camera.clone(); tokio::task::spawn(async move { // Wait for connection then start the countdown - let _ = rx.recv().await; + // By using a run_task we can delay the countdown until AFTER we are connected + let _ = camera + .run_task(|_cam| Box::pin(async move { AnyResult::Ok(()) })) + .await; log::debug!("Wakeup counting down"); sleep(Duration::from_secs(secs * 60)).await;