feat(utils/asyncMap): collection can be a promise

This commit is contained in:
Julien Fontanet 2017-07-04 14:06:40 +02:00
parent dd5c32f889
commit 084650e8ba

View File

@ -28,6 +28,7 @@ import {
all as pAll, all as pAll,
defer, defer,
fromCallback, fromCallback,
isPromise,
promisify, promisify,
reflect as pReflect reflect as pReflect
} from 'promise-toolbox' } from 'promise-toolbox'
@ -41,6 +42,10 @@ import {
// Similar to map() + Promise.all() but wait for all promises to // Similar to map() + Promise.all() but wait for all promises to
// settle before rejecting (with the first error) // settle before rejecting (with the first error)
export const asyncMap = (collection, iteratee) => { export const asyncMap = (collection, iteratee) => {
if (isPromise(collection)) {
return collection.then(collection => asyncMap(collection, iteratee))
}
let errorContainer let errorContainer
const onError = error => { const onError = error => {
if (errorContainer === undefined) { if (errorContainer === undefined) {