medium10 pts · first answer countsasync-awaitperformance
Three awaits, three times slower
Each call below takes about 100 ms and none depends on another. Roughly what does the log print, and what is the best fix?
const wait = (ms, v) => new Promise((r) => setTimeout(() => r(v), ms))
async function loadPage() {
const t = Date.now()
const user = await wait(100, 'user')
const posts = await wait(100, 'posts')
const ads = await wait(100, 'ads')
console.log(Math.round((Date.now() - t) / 100) * 100)
}