Skip to content

raineorshine/reduce-promises

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

reduce-promises

npm version Build Status

Serially executes promise-returning functions and reduces the results with the given accumulator.

Install

$ npm install --save reduce-promises

Usage

const { reducePromises, accumulate } = require('reduce-promises')

const functions = [
  () => Bluebird.delay(100, 'a'),
  () => Bluebird.delay(5, 'b'),
  () => Bluebird.delay(20, 'c')
]
reducePromises(functions, _.concat, []) // ['a', 'b', 'c']

The above concat reduction is common enough to warrant a shorthand function.

const functions = [
  () => Bluebird.delay(100, 'a'),
  () => Bluebird.delay(5, 'b'),
  () => Bluebird.delay(20, 'c')
]
accumulate(functions) // ['a', 'b', 'c']

License

ISC © Raine Revere

About

Serially executes promise-returning functions and reduces the results with the given accumulator.

Resources

License

Stars

Watchers

Forks

Packages

No packages published