promise-waterfall-native

1.0.1 • Public • Published

promise-waterfall

small package to use native JS promises

example

'use strict';
const Waterfall = require('../index');
 
const getSomeDataFromDB = () => {
  return new Promise((resolve) => {
    return setTimeout(() => {
      resolve([
        { id: 1 },
        { id: 2 }
      ]);
    }, 1000);
  });
};
 
const makeHttpCall = (result) => {
  const actions = result.map((obj) => {
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        console.log(`making call using obj.id: ${obj.id}`);
        const val = obj.id + 10;
        return resolve(val);
      }, 3000);
    });
  });
  return Promise.all(actions);
};
 
Waterfall([getSomeDataFromDB, makeHttpCall])
.then((results) => {
  // results should be an array with two items [11,12]
  console.log(results);
})
.catch((err) => {
  console.log(err);
});
 

For more example checkout the tests and the example directory

License [DWTFYW]

Do what the fuck you want with this free to change/copy/etc..

Package Sidebar

Install

npm i promise-waterfall-native

Weekly Downloads

3

Version

1.0.1

License

MIT

Last publish

Collaborators

  • doron2402