MediumEvent Loop & Promises🐛 Debug Challenge

Incorrect Promise.all Settlement

Fixed Code

const promises = [Promise.resolve(1), Promise.resolve(2), Promise.reject(3)]; Promise.allSettled(promises).then(results => console.log(results)).catch(error => console.log('Promise.allSettled rejected with reason:', error));

Bug Explained

Bug: The bug is due to using Promise.all, which rejects as soon as one of the promises in the array rejects.

Explanation: The original code uses Promise.all, which rejects as soon as one promise in the array rejects. In contrast, Promise.allSettled waits for all promises to either resolve or reject and returns an array of objects describing the outcome of each promise. The fix involves replacing Promise.all with Promise.allSettled to get the desired output.

Key Insight: The difference between Promise.all and Promise.allSettled and when to use each.

More Event Loop & Promises Debug Challenges

EasyMissing return in Promise chain drops valueMediumAsync function result is a Promise — not awaitedMediumSequential awaits for independent operations

Practice spotting bugs live →

38 debug challenges with AI hints

🐛 Try Debug Lab