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)
}Discussion 0
Join free to post in the discussion.
Related questions
- try/catch around an async callFull Stack Developer
- map with an async callbackFull Stack Developer
- Measuring speed in dev modeFull Stack Developer
- The N+1 query problemFull Stack Developer
- Caching hashed static filesFull Stack Developer
- One failing widget breaks the dashboardFull Stack Developer
- ETag and If-None-MatchFull Stack Developer
- One report slows every requestFull Stack Developer