webusb
webusb copied to clipboard
Use async/await
Not going to open a PR for this because I haven't tested it beyond compilation, and not sure it's something you'll want.
Switching the code to using async
/await
instead of manually creating promises can simplify some of the code, reduces indentation, and shaves 90 lines off the source.
See 5902723453e7f7c215a862d838882f5904dde621 for a commit that switches most code over to this pattern.
In particular, I think devicetoUSBDevice
simplifies nicely, as does openDevice
. It also makes the code from #39 more robust, as Promise.all
will short-circuit if one of the promises rejects, moving on to closing the adapter while the other promises are still unresolved, which might cause an error.
Some food for thought.
Aync/await in typescript created bulky code when this library was initially written, so it was avoided. However I'm keen to switch to this method of doing things in a lot of my libraries. The problem is time and balancing potential bug introductions with new features :)