News for hackers. Stuff that matters.
Re:Mistakes we make using JavaScript Promises by twooster on Friday July 05, 2019 @02:33AM (#20360315)
A bigger danger still would be:

  const userPromise = fetchUser(id)
  const itemPromise = fetchItem(itemId)
  // Do stuff, maybe even more async stuff
  const item = await itemPromise
  const user = await userPromise
Since those promises haven't been awaited until later in the code, they could throw and result in an unhandledRejection, which would be pretty bad. Promise.all is much safer since it instantly awaits both promises.

There are no comments on this comment yet.