>
I've mucked around a fair bit with JS's async and never felt like it got in the way.When functions return more than one Promise, or when one chains async functions calls, it isn't really clear Errors from which functions are likely to break out and result in an unhandled exception (read also: https://archive.is/ULT7P).
For example, does trapAllErrs() below trap 'em all? Not really. Why? The answer involves understanding the microtask queue and its place in the event loop.
// traps all errors from a1 and a2, or so we hope
async function trapAllErrs() {
try {
const p = Promise.all([a1(), a2()])
const results = await p
} catch (err) {}
}
// sync code in a1 never throws
async function a1() {
// do something sync
// ...
// a3 and a4 may throw errs
return Promise.any([a3(), a4()])
}
// sync code in a2 may throw
async function a2() {
// do something sync
// ...
// a5 never throws
const x = await a5()
// ...
return ans
}