Skip to content
RED SAGSkills
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)
}
Choose one answer