https://github.com/zewish/prottle
Promise.all() throttle
https://github.com/zewish/prottle
batches promise throttle
Last synced: 2 months ago
JSON representation
Promise.all() throttle
- Host: GitHub
- URL: https://github.com/zewish/prottle
- Owner: zewish
- Created: 2016-10-08T19:52:14.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-03-21T10:27:27.000Z (almost 5 years ago)
- Last Synced: 2025-10-17T23:08:32.007Z (3 months ago)
- Topics: batches, promise, throttle
- Language: JavaScript
- Size: 25.4 KB
- Stars: 14
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://www.npmjs.com/package/prottle)
[](https://github.com/zewish/prottle/actions?query=workflow%3Abuild)
[](https://www.npmjs.com/package/prottle)
Promise.all() throttle - Prottle
- Executes promise-returning functions in batches;
- Once batch 1 is finished it's time for the next one;
- Backend - Node 4.0+ supported;
- Frontend - works with the env preset using babel. Use a Promise polyfill for IE.
Installation
------------
```bash
$ npm install prottle --save
```
Example - resolved
------------------
```js
const prottle = require('prottle');
prottle(2, [
// batch 1
() => Promise.resolve(1),
() => Promise.resolve(2),
// batch 2
() => Promise.resolve(3),
() => new Promise((resolve, reject) => {
setTimeout(() => resolve(4), 3000);
}),
// batch 3
() => Promise.resolve(5),
])
.then(res => {
console.log(res); // [ 1, 2, 3, 4, 5 ]
});
```
Example - rejected
------------------
```js
const prottle = require('prottle');
prottle(2, [
() => Promise.resolve('yay'),
() => Promise.reject('beep boop'),
() => Promise.resolve('wow')
])
.catch(err => {
console.log(err); // beep boop
});
```
Works with returned values too!
-------------------------------
```js
const prottle = require('prottle');
prottle(2, [
() => 1,
() => 2,
() => 3
])
.then(res => {
console.log(res); // [ 1, 2, 3 ]
});
```