🟑 MediumAsync BugsπŸ› Debug Challenge

Sequential awaits killing performance

Buggy Code β€” Can you spot the issue?

async function getDashboard(userId) {
  const user = await fetchUser(userId);
  const posts = await fetchPosts(userId);
  return { user, posts };
}

Fixed Code

async function getDashboard(userId) {
  const [user, posts] = await Promise.all([
    fetchUser(userId),
    fetchPosts(userId)
  ]);
  return { user, posts };
}

Bug Explained

Bug: The two fetches run sequentially. fetchPosts waits for fetchUser to finish even though they're independent.

Explanation: Promise.all fires both requests simultaneously. If each takes 500ms, sequential = 1000ms, parallel = 500ms. Always parallelize independent async operations.

Key Insight: Sequential awaits for independent operations is a performance bug. Use Promise.all for parallel execution.

More Async Bugs Debug Challenges

🟒 EasyMissing await causes wrong resultβ†’πŸŸ‘ MediumSwallowed error in async functionβ†’πŸ”΄ HardAsync function in forEachβ†’πŸ”΄ HardRace condition in state updateβ†’

Practice spotting bugs live β†’

38 debug challenges with AI hints

πŸ› Try Debug Lab