From 084650e8ba6ef272e0dddd93244f61322ae74ea3 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Tue, 4 Jul 2017 14:06:40 +0200 Subject: [PATCH] feat(utils/asyncMap): collection can be a promise --- src/utils.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/utils.js b/src/utils.js index 1b497e14a..cf74b17ac 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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) {