user1189352
user1189352

Reputation: 3875

How can I wait for multiple promises to all be done before using their return data for another function call?

Unless I'm mistaken, I would like to get the values from 3 different promises and use what they return to call a function. I tried looking at chaining promises and Promise.all but I don't think that solves what I'm looking for?

What I would like to do is something like this:

somePromise( someParam ) => ( someReturnObj1 => {

});

somePromise2( someParam ) => ( someReturnObj2 => {

});

somePromise3( someParam ) => ( someReturnObj3 => {

});

// I would like to call this after getting all the data from those 3 promises
callSomeFunc( someReturnObj1, someReturnObj2, someReturnObj3 );

Is this possible?

Upvotes: 1

Views: 46

Answers (1)

Thiago Furtado
Thiago Furtado

Reputation: 118

Try this:

Promise.all([promise1,promise2]).then(result => {
    resultFromPromise1 = result[0];
    resultFromPromise2 = result[1];
});

Upvotes: 4

Related Questions