Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- figma
- ps
- SOLID
- vscode
- API
- mongo
- ts
- Express
- nodejs
- CV
- DB
- html
- threejs
- sqlite
- python
- frontend
- js
- DM
- UI
- C++
- ML
- GAN
- postgresql
- Linux
- PRISMA
- PyTorch
- review
- Git
- react
- CSS
Archives
- Today
- Total
아카이브
[JS] Syntax | 09. Promise.all() 본문
.all()은 여러 개의 Promise를 일괄적으로 처리할 때 사용합니다.
.all의 인자로는 Promise 객체의 배열 등을 넘겨줄 수 있습니다.
const promises = []
const asyncFunc = async (i) => {
const res = await fetch(`http://.../${i}`)
console.log(res)
}
for (let i=0; i<10; i++) {
// promises 배열에 Promise 객체를 추가합니다.
promises.push(asyncFunc(i))
}
// 10개의 Promise들이 모두 끝날 때 까지 대기합니다.
const result = await Promise.all(promises)
console.log(result)
Promise.all()은 배열의 모든 Promise가 fufiled 상태가 될 때 fulfiled 상태가 됩니다.
만약 하나 이상의 요소가 rejected 상태가 된다면, Promise.all() 역시 rejected가 됩니다.
728x90
'Language > JavaScript' 카테고리의 다른 글
[JS] Library | 02. Papaparse (1) | 2024.12.10 |
---|---|
[JS] Library | 01. Superstruct (0) | 2024.08.25 |
[JS] Syntax | 08. .then() (0) | 2024.07.27 |
[JS] Syntax | 07. await & async (0) | 2024.07.25 |
[JS] Syntax | 06. Promise (1) | 2024.07.24 |
Comments