Skip to content

Commit d228c55

Browse files
authored
Merge pull request #1 from Julusian/fix/cpu-spinloop
fix: avoid cpu spinloop
2 parents 11bf3a4 + ce1e67e commit d228c55

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ impl Emitter {
4040

4141
tokio::spawn(async move {
4242
loop {
43-
while !*listeners_rx.borrow() {
44-
// Wait for an event to be attached
43+
// Async-wait until at least one listener is attached
44+
if listeners_rx.wait_for(|v| *v).await.is_err() {
45+
return;
4546
}
4647

4748
let mut watch_stream = nusb::watch_devices().unwrap();

0 commit comments

Comments
 (0)