Skip to content

Commit 15a4c9e

Browse files
committed
main: wait for bluetooth gracefully shutdown before next iteration
1 parent 66e4d0e commit 15a4c9e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,12 @@ async fn tokio_main(
123123
error!("{} 🔌 USB init error: {}", NAME, e);
124124
}
125125

126+
let bt_stop;
126127
loop {
127128
match bluetooth_setup_connection(advertise, connect, tcp_start.clone()).await {
128129
Ok(state) => {
129130
// we're ready, gracefully shutdown bluetooth in task
130-
tokio::spawn(async move { bluetooth_stop(state).await });
131+
bt_stop = tokio::spawn(async move { bluetooth_stop(state).await });
131132
break;
132133
}
133134
Err(e) => {
@@ -141,6 +142,9 @@ async fn tokio_main(
141142
usb.enable_default_and_wait_for_accessory(accessory_started.clone())
142143
.await;
143144

145+
// wait for bluetooth stop properly
146+
let _ = bt_stop.await;
147+
144148
// wait for restart
145149
need_restart.notified().await;
146150

0 commit comments

Comments
 (0)