Skip to content

Bite size function examples:

Juan Sebastián Gaitán Villamizar edited this page Nov 20, 2017 · 1 revision

Immutable sequence of promise/s requests.

/**
* @argument Array items
* @argument Async Function asyncFunction
* @return [Promise]
*/
function getInSequence(items, asyncFunction) {
return items.reduce((previous, item) => (
previous.then(accumulator => (
asyncFunction(item).then(result => accumulator.concat(result))
))
), Promise.resolve([]));
}

Source


Clone this wiki locally