Skip to content

Commit

Permalink
fix: run simulator handling no actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Devdutt Shenoi committed Sep 22, 2023
1 parent 9f157ec commit 189cc18
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions uplink/src/collector/simulator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,31 @@ pub async fn start(
spawn_data_simulators(device, tx.clone());

loop {
select! {
action = actions_rx.as_ref().unwrap().recv_async(), if actions_rx.is_some() => {
let action = action?;
spawn(ActionResponse::simulate(action, tx.clone()));
if let Some(actions_rx) = actions_rx.as_ref() {
select! {
action = actions_rx.recv_async() => {
let action = action?;
spawn(ActionResponse::simulate(action, tx.clone()));
}
event = rx.recv_async() => {
match event {
Ok(Event::ActionResponse(status)) => bridge_tx.send_action_response(status).await,
Ok(Event::Data(payload)) => bridge_tx.send_payload(payload).await,
Err(_) => {
error!("All generators have stopped!");
return Ok(())
}
};
}
}
event = rx.recv_async() => {
match event {
Ok(Event::ActionResponse(status)) => bridge_tx.send_action_response(status).await,
Ok(Event::Data(payload)) => bridge_tx.send_payload(payload).await,
Err(_) => {
error!("All generators have stopped!");
return Ok(())
}
};
} else {
match rx.recv_async().await {
Ok(Event::ActionResponse(status)) => bridge_tx.send_action_response(status).await,
Ok(Event::Data(payload)) => bridge_tx.send_payload(payload).await,
Err(_) => {
error!("All generators have stopped!");
return Ok(());
}
}
}
}
Expand Down

0 comments on commit 189cc18

Please sign in to comment.