LearnFrenzy
Sign in Take a free test

Async/Await · Async/Await MCQ · Question 6

Running awaits in parallel Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 6 Back to Exercise

getUser() and getOrders() are independent and each takes 1 second. Which code finishes in about 1 second?

  • A const u = await getUser(); const o = await getOrders();
  • B await getUser(); await getOrders();
  • C const [u, o] = await Promise.all([getUser(), getOrders()]); Correct
  • D await (getUser(), getOrders());
Correct Answer: Option C

Promise.all starts both before waiting. Two sequential awaits take about 2 seconds; the comma version only awaits the second.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links