Skip to content

Commit b481980

Browse files
committed
feat: improve device watching initialization with error handling
1 parent b148484 commit b481980

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

src/lib.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ impl Emitter {
5050

5151
let callbacks = self.callbacks.clone();
5252
let mut listeners_rx = self.listeners_tx.subscribe();
53+
let mut watch_stream = match nusb::watch_devices() {
54+
Ok(watch_stream) => watch_stream,
55+
Err(e) => {
56+
self.initialized.store(false, Ordering::Release);
57+
return Err(napi::Error::from_reason(format!("init error: {e}")));
58+
}
59+
};
5360

5461
tokio::spawn(async move {
5562
loop {
@@ -58,10 +65,6 @@ impl Emitter {
5865
return;
5966
}
6067

61-
let mut watch_stream = match nusb::watch_devices() {
62-
Ok(watch_stream) => watch_stream,
63-
Err(_) => return,
64-
};
6568
loop {
6669
tokio::select! {
6770
_ = listeners_rx.changed() => {

0 commit comments

Comments
 (0)