thegecko / webusb

Node.js implementation of the WebUSB Specification
https://thegecko.github.io/webusb/
MIT License
183 stars 27 forks source link

Fix: Unhandled Promised rejection. #58

Closed nodech closed 4 years ago

nodech commented 4 years ago

Rejection from retryPromise is not handled from time to time. I noticed this when testing connect, disconnect listeners and rapidly connect/disconnect usb device. (Actually it's changing interface)

I believe rewrite to async/await(https://github.com/thegecko/webusb/issues/54) will help catch these errors, promises are not readable enough and it's hard to see if error is propagation properly.

Example code to reproduce:

usb.on('connect', (event) => {
  console.log('Device connected.');
});

usb.on('disconnect', (event) => {
  console.log('Connected.');
});

// request device so we can track the connect/disconnect events
usb.requestDevice({
  filters: [{}]
});