promise.js 380 B

123456789
  1. // run `fn` in serie for all values, and resolve with an array of the resultss
  2. // inspired by https://stackoverflow.com/a/50506360/1314820
  3. export function mapSeries(values, fn) {
  4. return values.reduce((promiseChain, value) => {
  5. return promiseChain.then(chainResults =>
  6. fn(value).then(currentResult => [...chainResults, currentResult])
  7. )
  8. }, Promise.resolve([]))
  9. }