promise-infinite
alternative Promise.all for handling very many promises
Last updated 8 months ago by roryrjb .
MIT · Original npm · Tarball
$ cnpm install promise-infinite 
SYNC missed versions from official npm registry.

promise infinite

NPM version Build status License Code style

alternative Promise.all for handling very many promises

Installation

$ npm install --save promise-infinite

...or:

$ yarn add promise-infinite

Motivation

This module is for when you need to throw hundreds or even thousands of Promises at a problem. Say you are doing lots of small HTTP requests or stating thousands of files on the filesystem, instead of doing async work in a serial manner just Array.prototype.map an array of URLs or filenames to a Promise interface (or create a wrapper) for the IO work you need to do and then promiseInfinite(yourArrayOfPromises) and it will just handle it.

If you use Promise.all on a lot of requests it will just choke, whether the JavaScript runtime or the OS because of too much IO in one go, this module just breaks down the work into more manageable chunks, plus if there are any Promise rejections it will still continue with the work load and return a list of rejections at the end.

Usage

const promiseInfinite = require('promise-infinite')

const ops = [
  new Promise(resolve => {
    // async work
    resolve()
  }),

  // hundreds or thousands of promises
]

promiseInfinite(ops)
  .then(results => {
    // results is an array containing the output
    // of each promise that resolved successfully

    // there is also a `.rejected` property with
    // an array of promises that were rejected
    // these could then be tried again for example
  })
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
  • co ^4.6.0
Dev Dependencies (5)
Dependents (2)

Copyright 2014 - 2016 © taobao.org |