Skip to content Skip to sidebar Skip to footer

How To Chain A Promise.all With Other Promises?

I want to execute my code in the following order: Promise 1 Wait for 1 to be done, then do Promise 2+3 at the same time Final function waits for Promise 2+3 to be done I'm having

Solution 1:

Just return Promise.all(...

getPromise1().then(() => {
  returnPromise.all([getPromise2(), getPromise3()]);
}).then((args) =>console.log(args)); // result from 2 and 3

Solution 2:

I know it's an old thread, but isn't

() => {returnPromise.all([getPromise2(), getPromise3()]);}

a little superfluous? The idea of fat arrow is that you can write it as:

() => Promise.all([getPromise2(), getPromise3()])

which makes the resulting code somewhat clearer:

getPromise1().then(() =>Promise.all([getPromise2(), getPromise3()]))
.then((args) =>console.log(args)); // result from 2 and 3

Anyway, thanks for the answer, I was stuck with this :)

Post a Comment for "How To Chain A Promise.all With Other Promises?"