all-limit

0.0.1 • Public • Published

all-limit Build Status

Like Promise.all(), but with a concurrency limiter.

About

Promise.all() is great, but sometimes, you want to throttle the number of concurrent executions.

That's where all-limit shines.

Example

'use strict';

import all from 'all-limit';

all({
  limit: 3,
  list: [ 1, 2, 3, 4, 5, 6, 7, 8 ],
  promise(item, resolve, reject) {
    // item is a .shift()ed element of the list[]
    setTimeout(() => resolve('item: ' + item), 1000);
  }
})
  .then((results) => console.log('all done:', results))
  .catch((err) => console.log('error:', err));

all({ limit, list, promise })

  • limit - Number, the concurrency limiter.
  • list - Array, each element of the list is provided to the promise function.
  • promise - Function, (item, resolve, reject), item is an element of the list array. The resolve and reject arguments are standard Promise callbacks.

Versions

  • 0.0.1 - Initial release

Readme

Keywords

none

Package Sidebar

Install

npm i all-limit

Weekly Downloads

0

Version

0.0.1

License

MIT

Last publish

Collaborators

  • ben-bradley