Fix wait_for_bulb_command logic
This commit is contained in:
@ -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<ClientRequest>,
|
||||
client_messages: broadcast::Sender<ClientRequest>,
|
||||
cmd: mpsc::Sender<BulbCommand>,
|
||||
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<ClientRequest>,
|
||||
mut client_messages: broadcast::Receiver<ClientRequest>,
|
||||
) {
|
||||
loop {
|
||||
match client_messages.recv().await {
|
||||
|
||||
Reference in New Issue
Block a user