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