When to use promise.all()?

前端 未结 8 834
孤街浪徒
孤街浪徒 2020-12-02 17:27

This is more of a conceptual question. I understand the Promise design pattern, but couldn\'t find a reliable source to answer my question about promise.all():<

8条回答
  •  星月不相逢
    2020-12-02 17:46

    Promise.all-This method is useful for when you want to wait for more than one promise to complete or The Promise.all(iterable) method returns a promise that resolves when all of the promises in the iterable argument have resolved, or rejects with the reason of the first passed promise that rejects.

    2.Just use Promise.all(files).catch(err => { }) This throws an error if ANY of the promises are rejected.

    3.Use .reflect on the promises before .all if you want to wait for all promises to reject or fulfill

    1. Syntax -Promise.all(iterable);

提交回复
热议问题