728x90
반응형
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled
Promise.allSettled() - JavaScript | MDN
The Promise.allSettled() static method takes an iterable of promises as input and returns a single Promise. This returned promise fulfills when all of the input's promises settle (including when an empty iterable is passed), with an array of objects that d
developer.mozilla.org
Promise.allSettled는 JavaScript에서 여러 개의 약속을 동시에 처리하는 데 유용한 메서드이며,
모든 약속이 해결되거나 거부될 때까지 기다릴 수 있습니다.
// Create some sample promises
const promise1 = new Promise((resolve, reject) => setTimeout(resolve, 100, 'Promise 1 resolved'));
const promise2 = new Promise((resolve, reject) => setTimeout(reject, 200, 'Promise 2 rejected'));
const promise3 = new Promise((resolve, reject) => setTimeout(resolve, 300, 'Promise 3 resolved'));
// Use Promise.allSettled to handle all promises
Promise.allSettled([promise1, promise2, promise3])
.then((results) => {
results.forEach((result, index) => {
if (result.status === 'fulfilled') {
console.log(`Promise ${index + 1} fulfilled with value: ${result.value}`);
} else if (result.status === 'rejected') {
console.log(`Promise ${index + 1} rejected with reason: ${result.reason}`);
}
});
});
728x90
반응형
'Front > JS & jQuery' 카테고리의 다른 글
[js] moment.js 라이브러리 duration() 함수 (0) | 2024.08.13 |
---|---|
[js] moment.js diff() 함수 (0) | 2024.08.12 |
[js] event.target / event.currentTarget (0) | 2024.07.28 |
[jquery] $.each 객체가 컬렉션으로 사용되는 경우 (0) | 2024.07.12 |
[js] { ...data } 와 data 대입의 차이 (0) | 2024.07.11 |