From 939e4d97856343617cbe841554c99e9762e3839f Mon Sep 17 00:00:00 2001 From: Joakim Hulthe Date: Thu, 27 Oct 2022 22:53:43 +0200 Subject: [PATCH] Fix wait_for_bulb_command logic --- backend/src/tasks/lights.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/backend/src/tasks/lights.rs b/backend/src/tasks/lights.rs index b424752..0c2a4ab 100644 --- a/backend/src/tasks/lights.rs +++ b/backend/src/tasks/lights.rs @@ -40,7 +40,7 @@ pub async fn lights_task(state: &State) { .flat_map(|(bulb, schedule)| schedule.iter().map(move |(day, time)| (bulb, day, time))) .map(|(bulb, day, time)| { let handle = spawn(wake_task( - state.client_message.subscribe(), + state.client_message.clone(), cmd.clone(), bulb.clone(), *day, @@ -113,7 +113,7 @@ pub async fn lights_task(state: &State) { if let Some(time) = time { let handle = spawn(wake_task( - state.client_message.subscribe(), + state.client_message.clone(), cmd.clone(), id.clone(), day, @@ -136,7 +136,7 @@ pub async fn lights_task(state: &State) { } async fn wake_task( - mut client_messages: broadcast::Receiver, + client_messages: broadcast::Sender, cmd: mpsc::Sender, id: BulbId, day: Weekday, @@ -168,7 +168,7 @@ async fn wake_task( for brightness in (1..=75).map(|i| (i as f32) * 0.01) { select! { // abort if the client pokes the bulb - _ = wait_for_bulb_command(&id, &mut client_messages) => break, + _ = wait_for_bulb_command(&id, client_messages.subscribe()) => break, _ = sleep(Duration::from_secs(12)) => {} }; @@ -192,7 +192,7 @@ async fn wake_task( /// Wait until we receive a client request that mutates the given bulb async fn wait_for_bulb_command( bulb_id: &BulbId, - client_messages: &mut broadcast::Receiver, + mut client_messages: broadcast::Receiver, ) { loop { match client_messages.recv().await {