How to chain a Promise.all with other Promises?

后端 未结 2 466
说谎
说谎 2021-02-06 22:58

I want to execute my code in the following order:

  1. Promise 1
  2. Wait for 1 to be done, then do Promise 2+3 at the same time
  3. Final function waits for
2条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-06 23:04

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

    () => {return Promise.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 :)

提交回复
热议问题