1.0.2 • Published 2 years ago

await-waterfall v1.0.2

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

await-waterfall

A simple try-catch block that allows the use of throw whilst being asynchronous. This utilizes async/waterfall.

import waterfall from 'await-waterfall';

const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));

waterfall<String>([
  async () => {
    await delay(1000);

    return "Hello World!";
  },
  async (str: String) => {
    if (str)
      throw new Error("I GOT IT!");

    return "I DID NOT GET IT!";
  }
], (err, str) => {
  console.log(err, str) // "I GOT IT", null
});