Even with async/await, raw promises are still key to writing optimal concurrent javascript
Daniel Brain
51430

How about pulling the two separate “threads” into their own functions?

async function prepareToppings (sauceType) {
let sauce = await makeSauce(sauceType)
let cheese = await grateCheese(sauce.determineCheese())
  return {sauce, cheese}
}
async function makePizza (sauceType = 'red') {
let [dough, {sauce, cheese}] = await Promise.all([
makeDough(),
prepareToppings(sauceType)
])
  dough.add(sauce)
dough.add(cheese)
  return dough
}
Show your support

Clapping shows how much you appreciated Joe Zim’s JavaScript Corner’s story.