Wait until all promises complete even if some rejected

前端 未结 18 1919
醉酒成梦
醉酒成梦 2020-11-21 04:55

Let\'s say I have a set of Promises that are making network requests, of which one will fail:

// http://does-not-exist will throw a TypeError
va         


        
18条回答
  •  迷失自我
    2020-11-21 05:36

    I don't know which promise library you are using, but most have something like allSettled.

    Edit: Ok since you want to use plain ES6 without external libraries, there is no such method.

    In other words: You have to loop over your promises manually and resolve a new combined promise as soon as all promises are settled.

提交回复
热议问题