-
reject,resolve의 Promise속에서 결과가 중복되었을 경우 먼저 호출 된 것만 결과로 처리 된다.
PromiseResultOrder.ts
{ async function Pm1(name:string, bResolveFirst:boolean) { let rst1 = await new Promise((resolve, reject)=>{ if(bResolveFirst) { resolve(name+".resolve~ bResolveFirst:" + bResolveFirst); } reject(name+".reject~ bResolveFirst:" + bResolveFirst); if(!bResolveFirst) { resolve(name+".resolve~ bResolveFirst:" + bResolveFirst); } }).then((resolve)=>{ console.log("then " + resolve); return name+".then return~"; }).catch((reject)=>{ console.log("catch " + reject); return name+".catch return~"; }); return rst1; } async function Main1() { console.log("root start"); let pmt1 = Pm1("Pmt1", true) let pmt2 = Pm1("Pmt2", false) console.log("root " + await pmt2); console.log("root " + await pmt2); console.log("root end"); } Main1(); }
root start then Pmt1.resolve~ bResolveFirst:true catch Pmt2.reject~ bResolveFirst:false root Pmt2.catch return~ root Pmt2.catch return~ root end
'Html Css JavaScript' 카테고리의 다른 글
window load event (0) 2023.01.23 jQuery 설치 (0) 2023.01.23 Bootstrap 적용 준비 (0) 2023.01.22 html layout ex1 (float 적용) (0) 2023.01.22 Promise Ex 결과(resolve, reject)와 return값 (0) 2023.01.22 Promise Ex 결과(resolve, reject) 없을 경우 (0) 2023.01.22 Promise Ex 결과에서 재귀적 사용 (0) 2023.01.22 async await Ex2 (0) 2023.01.22