6. Promise 체인
아래와 같이 각각의 후속 처리 메서드들이 이어서 호출할 수 있도록 동작하는 이유는 해당 메서드들이 Promise 객체를 반환하기 때문
chain.js
const promise = new Promise(executor);
promise
.then((response) => console.log(`응답 결과: ${response}`))
.catch((error) => console.error(`error: ${error}`));
.finally(() => console.log('요청 수행 완료'));별도의 변수로 분리하여 확인해보기
chain.js
const promise = new Promise(executor);
const afterThen = promise.then((response) => console.log(`응답 결과: ${response}`));
const afterCatch = afterThen.catch((error) => console.error(`error: ${error}`));
const afterFinally = afterCatch.finally(() => console.log('요청 수행 완료'));Last updated on