1.0.0 • Published 6 years ago

smart-promises v1.0.0

Weekly downloads
25
License
ISC
Repository
-
Last release
6 years ago

Smart promises

A simple and helpful promises functions to work with Promises.

Installation

npm i smart-promises

promiseWaterfall

Each promise will be executed only after previous in promises array

const { promiseWaterfall } = require('smart-promises');

const pool = Array.map((item) => () => promiseReturnFunction(item));
promiseWaterfall(pool)
    .then((results) => {
        <!-- do stuff with results of execution each of promise -->
    });

promiseMapLimit

When you have array of promises and don't want to use Promise.all (mass execution all of promises) - you can use promiseMapLimit, that can help you runs promises small chunks with defined limit.

const { promiseWaterfall } = require('smart-promises');

const pool = Array.map((item) => () => promiseReturnFunction(item));
promiseMapLimit(pool, 5)
    .then((results) => {
        <!-- do stuff with results of execution each of promise -->
    });