flat-await
v1.0.0
Published
Ditch the try/catch block for async/await using destructuring.
Downloads
1
Readme
flat-await
When working with async/await
, we usually have to do this:
async function foo() {
try {
const bar = await baz();
. . .
} catch (e) {
console.error(e);
}
}
That sucks. Instead, flat-await
lets you do this:
import p from 'flat-await';
async function foo() {
const [err, bar] = await p(baz());
if (err) throw err;
. . .
}
Re-throwing the error will propagate it out, or you can do something else more appropriate.