medium10 pts · first answer countsnodejsasync-programmingperformance
Two awaits that could run together
About how many milliseconds does this handler log, and how can you speed it up?
const wait = (ms) => new Promise((r) => setTimeout(r, ms))
async function getUser() { await wait(300); return 'user' }
async function getOrders() { await wait(300); return 'orders' }
async function handler() {
const start = Date.now()
const user = await getUser()
const orders = await getOrders()
console.log(Date.now() - start)
}Discussion 0
Join free to post in the discussion.
Related questions
- Promise and setTimeout orderBackend Developer
- Slow email during signupBackend Developer
- What EXPLAIN tells youBackend Developer
- Asking for only a few fieldsBackend Developer
- Building a long string in a loopBackend Developer
- Checking if any rows existBackend Developer
- Latency versus throughputBackend Developer
- The N+1 query problemBackend Developer