npm

Check out our latest tech talk, "JavaScript Supply Chain Security" presented by VP of Security, Adam Baldwin.Watch it here »

prottle

1.0.3 • Public • Published

NPM version Build Status Downloads

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 ES2015 preset using babelify. Use a Promise polyfill for IE.

Installation

$ npm install prottle --save

Example - resolved

'use strict';
let 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

'use strict';
let 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!

'use strict';
let prottle = require('prottle');
 
prottle(2, [
    () => 1
    , () => 2
    , () => 3
])
.then(res => {
    console.log(res); // [ 1, 2, 3 ]
});

install

npm i prottle

Downloadsweekly downloads

86

version

1.0.3

license

BSD-2-Clause

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability