Promise.allSettled()
ES2020+Returns a promise that resolves after all of the given promises have either fulfilled or rejected, with an array of objects describing each outcome.
Syntax
Promise.allSettled(iterable)Parameters
iterable Iterable An iterable of promises
Return Value
A Promise that resolves with an array of result objects
Examples
Promise.allSettled([
Promise.resolve('성공'),
Promise.reject('실패'),
Promise.resolve('또 성공')
]).then(results => {
results.forEach(r => console.log(r.status));
}); 📌 When to Use
Use Promise.allSettled() when you want to know the outcome of all promises, even if some fail, such as batch operations where partial success is acceptable.
⚠️ Common Mistakes
Assuming allSettled rejects when a promise fails - it always resolves with status objects.
Not checking the status property to distinguish fulfilled from rejected results.
✅ Best Practices
Filter results by status: results.filter(r => r.status === "fulfilled").map(r => r.value).
Log failures while processing successes: separate handling for each outcome.
⚡ Performance Notes
Promise.allSettled() waits for ALL promises to settle, unlike Promise.all() which short-circuits on first rejection. Use when you need complete results.
🌍 Real World Example
Batch Email Sender
Send emails to multiple recipients, tracking which succeeded and which failed.
async function sendBulkEmails(recipients, emailContent) {
const sendPromises = recipients.map(email =>
sendEmail(email, emailContent)
.then(() => ({ email, sent: true }))
);
const results = await Promise.allSettled(sendPromises);
const report = {
total: recipients.length,
successful: results.filter(r => r.status === 'fulfilled').map(r => r.value.email),
failed: results.filter(r => r.status === 'rejected').map((r, i) => ({
email: recipients[i],
error: r.reason.message
}))
};
console.log(`Sent: ${report.successful.length}, Failed: ${report.failed.length}`);
return report;
}