정ㅇr 2022. 12. 4. 02:28
728x90

해당 단원은 예제 기반으로 실행하고 공부하는게 좋아서 따로 글을 작성하지 않았습니다.

대신 관련 내용을 첨부했습니다.

 

비동기 함수와 이벤트 핸들러 설명을 위한 그림

 

45-10, 11 프로미스 생성

 

45-12 fulfilled된 프로미스

45-13 rejected된 프로미스

 

const fulfilled = new Promise((resolve, reject) => {
	setTimeout(() => {
    	if (Math.random() > 0.5) resolve(1);
        else reject(2);
    }, 3000);
}).then(res => console.log(res))
.catch(err => console.log(err))

 

const prom = (val) => new Promise((resolve, reject) => {
	setTimeout(() => {
    	if (val > 0.5) resolve(1);
        else reject(2);
    }, 1000);
}).then(res => console.log(res))
.catch(err => console.error(err))
.finally(() => console.log('finally'))
.then(() => console.log('then'))

 

45-14, 15, 16, 17, 18 프로미스 후속 처리 메서드 (then, catch, finally)

 

45-19 ~ 45-23 프로미스의 에러 처리

 

45-24, 25 프로미스 체이닝

 

45-26 ~ 45-38 프로미스 정적 메서드

 

45-39 마이크로태스크 큐

 

45-40 ~ 끝까지 fetch 함수

 

https://github.com/wikibook/mjs/blob/master/45.md

 

GitHub - wikibook/mjs: 《모던 자바스크립트 Deep Dive》 예제 코드

《모던 자바스크립트 Deep Dive》 예제 코드. Contribute to wikibook/mjs development by creating an account on GitHub.

github.com

 

https://poiemaweb.com/es6-promise

 

Promise | PoiemaWeb

Promise는 비동기 처리가 성공(fulfilled)하였는지 또는 실패(rejected)하였는지 등의 상태(state) 정보를 갖는다. Promise는 Promise 생성자를 통해 인스턴스화한다. Promise 생성자는 비동기 작업을 수행할 콜

poiemaweb.com

 

 

 

반응형