← Todas las publicaciones
post2 de abril de 2026
Promise.allSettled vs Promise.all
#javascript#promises#async

javascript
const p1 = fetch('/api/user');
const p2 = fetch('/api/posts'); // suppose this fails
// Promise.all — rejects immediately on first failure
Promise.all([p1, p2]).catch(err => console.error('All failed:', err));
// Promise.allSettled — waits for all, reports each result
const results = await Promise.allSettled([p1, p2]);
results.forEach(r => {
if (r.status === 'fulfilled') console.log(r.value);
else console.warn('Failed:', r.reason);
});