Package Exports
- promise-sequential
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (promise-sequential) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
promise-sequential
Simple like Promise.all(), but sequentially!
Installation
npm install --save promise-sequential
Usage
const sequential = require('promise-sequential');
const items = [
() => new Promise( ... )
() => new Promise( ... )
() => new Promise( ... )
];
sequential(items)
.then(res => {
// ...
})
.catch(err => {
// ...
})
There is only one difference between Promise.all usage and promise-sequential usage: promise-sequential receive an Array of functions that each returns a promise.
Each function brings three params:
Name | Description |
---|---|
previousResponse | The response of previous iteration |
responses | All responses received at the time |
count | The current count. |
More complex usage
const sequential = require('promise-sequential');
const array = [1,2,3,4,5];
sequential(array.map((item) => {
return function(previousResponse, responses, count) {
return new Promise(resolve => {
setTimeout(() => {
resolve(item)
}, 1000)
})
}
}))
.then(res => {
// ...
})
.catch(err => {
// ...
})