1.0.0 • Published 5 years ago
promise-sequential-throttle v1.0.0
promise-sequential-throttle
Execute promise in sequence, with throttle.
Installation
npm install --save promise-sequential-throttle
sequential.all(sequence, promiseFunction, throttle);
sequence:
<array>
|<generator>
type: array
array of parameters that pass in to promiseFunction
type: generator function
a function that returns a generater object, which generates parameters that pass in to promiseFunction
type: generator object
a generater object, which generates parameters that pass in to promiseFunctionpromiseFunction:
<function>
type: function
task execution function, pass in a parameter, returns a promisethrottle:
<number>
type: number
throttle limit of concurrent executions
Usage
Parameter Array
const sequential = require('promise-sequential-throttle');
const params = [1,2,3,4,5];
sequential.all(params,
param => {
return new Promise(resolve=> {
setTimeout(()=>{
console.log(param);
})
});
},
2);
Generator Function
const sequential = require('promise-sequential-throttle');
const params = [1,2,3,4,5];
const generatorFunction = function* () {
for (let i = 0; i < params.length; i++)
yield params[i];
};
sequential.all(generatorFunction,
param => {
return new Promise(resolve=> {
setTimeout(()=>{
console.log(param);
})
});
},
2);
Generator Object
const sequential = require('promise-sequential-throttle');
const params = [1,2,3,4,5];
const generatorObject = function* () {
for (let i = 0; i < params.length; i++)
yield params[i];
}();
sequential.all(generatorObject,
param => {
return new Promise(resolve=> {
setTimeout(()=>{
console.log(param);
})
});
},
2);
1.0.0
5 years ago