Building Your Learning Module...
Getting things ready for you!
Find videos you like?
Save to resource drawer for future reference!
Promise methods let you work with multiple promises at once. Run them in parallel, race them, or handle all results together!
Promise.all() waits for ALL promises to succeed. If ANY fails, the whole thing fails.
Returns array of all results in same order
Rejects immediately with the first error
Run multiple promises in parallel
Promise.race() resolves or rejects as soon as the FIRST promise settles (success or failure).
const slow = delay(3000, 'Slow');
const fast = delay(1000, 'Fast');
Promise.race([slow, fast])
.then(result => {
console.log('Winner:', result); // 'Fast'
});First to complete wins
Promise.allSettled() waits for ALL promises to complete, whether they succeed or fail. Always resolves!
Promise.allSettled([p1, p2, p3])
.then(results => {
// results = [
// { status: 'fulfilled', value: ... },
// { status: 'rejected', reason: ... },
// { status: 'fulfilled', value: ... }
// ]
});Get all results regardless of success/failure
Promise.any() resolves as soon as ANY promise succeeds. Ignores failures unless ALL fail.
const fail1 = Promise.reject('Error 1');
const fail2 = Promise.reject('Error 2');
const success = Promise.resolve('Success!');
Promise.any([fail1, fail2, success])
.then(result => {
console.log(result); // 'Success!'
});First to succeed wins
Need ALL results, fail if ANY fails
Need FIRST to finish (success or failure)
Need ALL results (never fails)
Need FIRST success (ignore failures)
const results = await Promise.all([...])