Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Promise 구현하기
Promise란 비동기 작업의 성공과 실패를 다루는 객체를 말한다. Promise는 ES6의 문법이다.
Promise가 ES6에 도입된 이유는 기존 Callback Function의 문제 때문이다. 사용자 인터랙션이 언제 발생할지 모르기 때문에 함수의 제어권을 함수로 넘겨주어 실행되도록 한다. 하지만 Callback의 Depth가 커진다면 읽기가 힘들어지는 가독성 문제와 에러처리를 하나하나 해주어야한다는 불편함도 있었다.
비동기에서 에러를 관리하기가 힘들다. 동기 코드가 모두 실행된 이후에 Callback Queue에서 Callback Function을 꺼내와 실행하기 때문이다.
Promise는 비동기 처리에서 발생하는 Callback Function의 문제점을 보완하여, 개발자들에게 더 나은 편의성을 제공하는 문법이다. 특히, 가독성을 유지하면서도 Callback Hell을 방지하고, 개별적인 에러 처리가 아닌 자동 에러 전파를 통해 더욱 효율적인 에러 관리가 가능하도록 설계되었다.
✅ 구현 목록
📄 구현 과정
State(pending, fulfilled, rejected)
정의queueMicroTask
활용하여 새로운 Promise를 반환하도록 구현then(undefined, onRejected)
의 특징을 활용then(onFinally, onFinally)
의 특징을 활용느낀 점.