I am trying to use a Promise.all
inside of a reduce
and cannot get my function
to work, unless there is only one user in my array. The starting object of the reduce
is a Promise
. The first time through the reduce
, the Promise
has .all
available on it. The second time through, the .all
is not available.
return UserQueries.addUsersOnCasefileCreate(input).then(users => {
return users.reduce((promise, user) => {
return promise.all([
AddressQueries.addAddress(user.address, user.userId, input.orgId),
EmailQueries.addEmail(user.emails, user.userId, input.orgId),
PhoneQueries.addPhones(user.phones, user.userId, input.orgId)
])
.then(() => Promise.resolve(user))
}, Promise);
})
How could I perform this operation?
promise
andPromise
, anyway. – Tatsuyuki Ishipromise
that is lower case is just the first argument of thereduce
referring to thePromise
as the initial object. It isn't a typo. – jhammPromise.prototype.all()
. OnlyPromise.all()
. – Tatsuyuki Ishipromise
from the first argument is thePromise
in the initial object. That is why it works the first time through the loop. That is whyPromise.all
is available at first. – jhamm