Yeah especially waiting for promises to resolve and parallel stuff with async/await.
For example i see this in a lot of my code reviews with new js programmers:
// does some parallel async stuff
arrayOfItems.forEach(async item => {
await doSomethingAsync(item)
})
doSomethingWhenDone()
This won't wait for the promise to actually resolve outside of the forEach and call doSomethingWhenDone(). If your program exist it will not wait for your async work to be done.
I believe this would wait for each promise to resolve before moving onto the next loop.
The Promise.all() solution allows each async call to happen async concurrently; only moving on once all promises resolve (regardless of the order in which they resolve).
12
u/pm_me_cute_rem_pics js/ux May 28 '19
Yeah especially waiting for promises to resolve and parallel stuff with async/await.
For example i see this in a lot of my code reviews with new js programmers:
This won't wait for the promise to actually resolve outside of the
forEachand calldoSomethingWhenDone(). If your program exist it will not wait for your async work to be done.either do:
Or if you like mapping over promises.
examples https://repl.it/repls/WeeklyColorfulGraduate