flat-await

1.0.0 • Public • Published

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.

Dependencies (1)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i flat-await

    Weekly Downloads

    1

    Version

    1.0.0

    License

    ISC

    Unpacked Size

    2.47 kB

    Total Files

    6

    Last publish

    Collaborators

    • johnhalbert