Skip to content

Execute all the promise tasks with rejection ignored and return the precise resolved values and rejected promises.

License

Notifications You must be signed in to change notification settings

simongong/precise-promise-all

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Execute all the promise tasks with rejection ignored and return the precise resolved values and rejected promises.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published