Re:Beware of Async/Await
by TheCoelacanth on Thursday July 30, 2020 @01:06PM
(#24000532)
That's true, but in my experience, they also just memorize the ".then(result =>" pattern and make exactly the same mistake.
[ Parent
| on HN ]
But I maintain that in the illustrated case - where you want to get all the different independent values and then combine them at the end - it's actually less ergonomic to do it the wrong way with .then(...) than it is to do it the right way.
Most ergonomic IMO is:
const getPeople = async () => (await Promise.all(...)).flat()
Without await this would be
const getPeople = () => Promise.all(...).then(arrs => arrs.flat())
The difference is slight to be sure, but I usually prefer the await approach.