Skip to content

Commit 189cc18

Browse files
author
Devdutt Shenoi
committed
fix: run simulator handling no actions
1 parent 9f157ec commit 189cc18

File tree

1 file changed

+24
-13
lines changed
  • uplink/src/collector/simulator

1 file changed

+24
-13
lines changed

uplink/src/collector/simulator/mod.rs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,20 +101,31 @@ pub async fn start(
101101
spawn_data_simulators(device, tx.clone());
102102

103103
loop {
104-
select! {
105-
action = actions_rx.as_ref().unwrap().recv_async(), if actions_rx.is_some() => {
106-
let action = action?;
107-
spawn(ActionResponse::simulate(action, tx.clone()));
104+
if let Some(actions_rx) = actions_rx.as_ref() {
105+
select! {
106+
action = actions_rx.recv_async() => {
107+
let action = action?;
108+
spawn(ActionResponse::simulate(action, tx.clone()));
109+
}
110+
event = rx.recv_async() => {
111+
match event {
112+
Ok(Event::ActionResponse(status)) => bridge_tx.send_action_response(status).await,
113+
Ok(Event::Data(payload)) => bridge_tx.send_payload(payload).await,
114+
Err(_) => {
115+
error!("All generators have stopped!");
116+
return Ok(())
117+
}
118+
};
119+
}
108120
}
109-
event = rx.recv_async() => {
110-
match event {
111-
Ok(Event::ActionResponse(status)) => bridge_tx.send_action_response(status).await,
112-
Ok(Event::Data(payload)) => bridge_tx.send_payload(payload).await,
113-
Err(_) => {
114-
error!("All generators have stopped!");
115-
return Ok(())
116-
}
117-
};
121+
} else {
122+
match rx.recv_async().await {
123+
Ok(Event::ActionResponse(status)) => bridge_tx.send_action_response(status).await,
124+
Ok(Event::Data(payload)) => bridge_tx.send_payload(payload).await,
125+
Err(_) => {
126+
error!("All generators have stopped!");
127+
return Ok(());
128+
}
118129
}
119130
}
120131
}

0 commit comments

Comments
 (0)