1

Two or more requests are sent simultaneously inside Promise.all. Then their responses are handled appropriately. But in case one of them is failed the rest of results is lost.

async init function ()
   const [userInfo, balance] = 
      await Promise.all([
          Promise.reject('get user info error'), // getUserInfo(), 
          Promise.resolve(5000) // getBalance()
      ])
   this.userInfo = userInfo
   this.balance = balance // it won't be initialized
}

Can that be handled without rewriting above code to old promise .. then().catch() style?

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
humkins
  • 9,635
  • 11
  • 57
  • 75
  • 2
    async/await and try...catch are just syntactic sugar for .then and .catch. No, this can't be handled with single async function and without .catch. – Estus Flask Feb 27 '18 at 17:03
  • 1
    @estus We could always replace `x.catch(h)` with `(async function() { try { return await x; } catch(e) { return h(e); }}())`, but we can't reasonably call this "syntactic sugar" any more :-) – Bergi Feb 27 '18 at 17:41

0 Answers0