Kevin 29b9a0c50c clean && clean html base | 4 years ago | |
---|---|---|
.. | ||
index.js | 4 years ago | |
license | 4 years ago | |
package.json | 4 years ago | |
readme.md | 4 years ago |
Map over promises serially
Useful as a side-effect mapper. Use p-map
if you don't need side-effects, as it's concurrent.
$ npm install --save p-map-series
const pMapSeries = require('p-map-series');
const keywords = [
getTopKeyword() //=> Promise
'rainbow',
'pony'
];
let scores = [];
const mapper = keyword => fetchScore(keyword).then(score => {
scores.push(score);
return {keyword, score};
});
pMapSeries(keywords, mapper).then(result => {
console.log(result);
/*
[{
keyword: 'unicorn',
score: 99
}, {
keyword: 'rainbow',
score: 70
}, {
keyword: 'pony',
score: 79}
]
*/
});
Returns a Promise
that is fulfilled when all promises in input
and ones returned from mapper
are fulfilled, or rejects if any of the promises reject. The fulfilled value is an Array
of the mapper
created promises fulfillment values.
Type: Iterable<Promise|any>
Mapped over serially in the mapper
function.
Type: Function
Expected to return a value. If it's a Promise
, it's awaited before continuing with the next iteration.
MIT © Sindre Sorhus