Wondering what’s next for npm?Check out our public roadmap! »

precise-promise-all

0.0.2 • Public • Published

precise-promise-all

npm version

Promise.all is rejected if one of the elements is rejected and Promise.all fails fast: If you have four promises which resolve after a timeout, and one rejects immediately, then Promise.all rejects immediately.

from Promise All - MDN

There are some cases which Promise.all is not applicable for:

  • Not all tasks are ensured to get executed due to fast-fail.
  • You don't know the resolved values in detail, only the overall result
  • You don't know rejected tasks which you may want to process afterwards.

Therefore, I made this precise-promise-all, which will

  • execute all the promise tasks
  • return the precise resolved values and rejected promises as well.

Install

$ npm install --save precise-promise-all

Usage

precise-promise-all provides two APIs which work in different way but yield the same result:

  • parallel(iterable)
  • sequential(iterable)

Example

const PrecisePromiseAll = require('precise-promise-all');
 
// iterable is an array of `() => somethingThatCreatesAPromise()`
PrecisePromiseAll.parallel(iterable)
.then((result) => {
    // result consists of {resolved, rejected} in which
    // resolved looks like {index1: resolvedValue1, ...} and
    // rejected looks like {index2: iterable[index2]}.
    // So you can consume values of resolved promises and
    // hanlde those rejected promises afterwards
});

License

MIT

Install

npm i precise-promise-all

DownloadsWeekly Downloads

3

Version

0.0.2

License

MIT

Last publish

Collaborators

  • avatar