DEV Community

Discussion on: Asynchronous code with async/await

Collapse
 
math2001 profile image
Mathieu PATUREL • Edited

Quick tip: the async/await version of Promise.all:

async function main() {
  // NO! You're wait for one at a time, which isn't good

  let themes = await getThemes()
  let content = await getContent()

  // YES! You wait for both at the same time

  let themesPromise = getThemes() // this doesn't block anything
  let contentPromise = getContent() // this either

  let [themes, content] = [await themesPromise, await contentPromise]
}
main()
Collapse
 
luckymore profile image
不长肉

can't get you...