[Node] Promist Chainging, Promist.all


[Node] Promist Chainging, Promist.all

Promise Chaining은 여러 개의 프로미스를 then으로 연결해주는 것이다. 테스트할 js 파일을 만들고 아래 소스를 추가한다. 아래 소스는 setTimeout을 사용하여 1초 후에 p1의 text를 찍고 3초 후에 p2의 텍스트를 찍는 소스다. 병렬적으로 실행 된다. (p1 실행 후 3초 뒤가 아닌 처음 실행 기준에서 3초) const p1 = new Promise((resolve, reject) => { setTimeout( () => { resolve({ p1_text : "p1의 텍스트"}); }, 1000); }); const p2 = new Promise((resolve, reject) => { setTimeout( () => { resolve({ p2_text : "p2의 텍스트"}); }, 3000); }); p1.then( (result1) => { console.log("p1 = " + result1.p1_text); // return으로 promise 객...


#all #프로미스 #자바스크립트 #노드 #promisechinging #promiseall #promise #nodejs #node #javascript #chinging #프로미스올

원문링크 : [Node] Promist Chainging, Promist.all