When to use promise.all()?

前端 未结 8 824
孤街浪徒
孤街浪徒 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

    It's hard to answer these questions as they are the type that tend to answer themselves as one uses the available APIs of a language feature. Basically, it's fine to use Promises any way that suits your use case, so long as you avoid their anti-patterns.

    What is(are) the correct scenario(s) to use promise.all()

    Any situation in which an operation depends on the successful resolution of multiple promises.

    Are there any best practices to use promise.all()? Should it be ideally used only if all of the promise objects are of the same or similar types?

    Generally, no and no.

提交回复
热议问题