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)))
|
.flat_map(|(bulb, schedule)| schedule.iter().map(move |(day, time)| (bulb, day, time)))
|
||||||
.map(|(bulb, day, time)| {
|
.map(|(bulb, day, time)| {
|
||||||
let handle = spawn(wake_task(
|
let handle = spawn(wake_task(
|
||||||
state.client_message.subscribe(),
|
state.client_message.clone(),
|
||||||
cmd.clone(),
|
cmd.clone(),
|
||||||
bulb.clone(),
|
bulb.clone(),
|
||||||
*day,
|
*day,
|
||||||
@ -113,7 +113,7 @@ pub async fn lights_task(state: &State) {
|
|||||||
|
|
||||||
if let Some(time) = time {
|
if let Some(time) = time {
|
||||||
let handle = spawn(wake_task(
|
let handle = spawn(wake_task(
|
||||||
state.client_message.subscribe(),
|
state.client_message.clone(),
|
||||||
cmd.clone(),
|
cmd.clone(),
|
||||||
id.clone(),
|
id.clone(),
|
||||||
day,
|
day,
|
||||||
@ -136,7 +136,7 @@ pub async fn lights_task(state: &State) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn wake_task(
|
async fn wake_task(
|
||||||
mut client_messages: broadcast::Receiver<ClientRequest>,
|
client_messages: broadcast::Sender<ClientRequest>,
|
||||||
cmd: mpsc::Sender<BulbCommand>,
|
cmd: mpsc::Sender<BulbCommand>,
|
||||||
id: BulbId,
|
id: BulbId,
|
||||||
day: Weekday,
|
day: Weekday,
|
||||||
@ -168,7 +168,7 @@ async fn wake_task(
|
|||||||
for brightness in (1..=75).map(|i| (i as f32) * 0.01) {
|
for brightness in (1..=75).map(|i| (i as f32) * 0.01) {
|
||||||
select! {
|
select! {
|
||||||
// abort if the client pokes the bulb
|
// 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)) => {}
|
_ = 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
|
/// Wait until we receive a client request that mutates the given bulb
|
||||||
async fn wait_for_bulb_command(
|
async fn wait_for_bulb_command(
|
||||||
bulb_id: &BulbId,
|
bulb_id: &BulbId,
|
||||||
client_messages: &mut broadcast::Receiver<ClientRequest>,
|
mut client_messages: broadcast::Receiver<ClientRequest>,
|
||||||
) {
|
) {
|
||||||
loop {
|
loop {
|
||||||
match client_messages.recv().await {
|
match client_messages.recv().await {
|
||||||
|
|||||||
Reference in New Issue
Block a user