자바스크립트는 기본적으로 동기로 작동하며 콜스택에 쌓인다.
그러나 promise 및 setTimeout과 같이 비동기로 작동하는 코드들은 백그라운드로 넘겨지고
콜백큐에 쌓이고, 콜스택이 비어지면 순차적으로 콜스택으로 넘어간다.
const a = axios.get()
const b = axios.get()
const c = axios.get()
const d = axios.get()
promise.all([a,b,c,d]).then((result)=>{}).catch((error)=>{})
promise.allSettled([a,b,c,d]).then((result)=>{}).catch((error)=>{})
promise.allSettled는 에러가 발생하지 않은 부분은 then에서 활용할 수 있다.
const p = new Promise((resolve,reject)=>{
console.log("이 부분은 동기")
})
console.log("두번째")
new Promise의 함수는 동기로 작동한다.
따라서 위의 코드를 실행하면
"이 부분은 동기"
"두번쨰"
순으로 반환 받는다.