Wait until all promises complete even if some rejected

前端 未结 18 2307
醉酒成梦
醉酒成梦 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:24

    Promise.all with using modern async/await approach

    const promise1 = //...
    const promise2 = //...
    
    const data = await Promise.all([promise1, promise2])
    
    const dataFromPromise1 = data[0]
    const dataFromPromise2 = data[1]
    

提交回复
热议问题