Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Your example is equal to

  await getThingAtIndex(1)
  await getThingAtIndex(2)
  await getThingAtIndex(3)
whereas the async for loop is equivalent to

  await Promise.all([
    getThingAtIndex(1),
    getThingAtIndex(2),
    getThingAtIndex(3)
  ])
Your example is valid syntax, but it executes each call synchronously.


The article says `This feature adds a new “for-await-of” loop that allows us to call async functions that return promises (or Arrays with a bunch of promises) in a loop. The cool thing is that the loop waits for each Promise to resolve before doing to the next loop.`. which seems to be in contention with what you say.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: