1.0.0 • Published 2 years ago

flat-await v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

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.