promise의 이해2
promise의 이해2
func1(10).then((res)=>{
func2(res).then((res)=>{
func3(res)
})
})
;
function func1(val_in){
return new Promise((resolve, reject)=>{
console.log('func1실행: val_in=' + val_in);
setTimeout(()=>{
funcProcessing('func1', val_in).then((res)=>{
resolve(res);
})
}, 2000);
})
}
function func2(val_in){
return new Promise((resolve, reject)=>{
console.log('func2실행: val_in=' + val_in);
setTimeout(()=>{
funcProcessing('func2', val_in).then((res)=>{
resolve(res);
})
}, 5000);
})
}
function func3(val_in){
return new Promise((resolve, reject)=>{
console.log('func3실행: val_in=' + val_in);
setTimeout(()=>{
funcProcessing('func3', val_in).then((res)=>{
resolve(res);
})
}, 2000);
})
}
function funcProcessing(processName, val_in){
return new Promise((resolve, reject)=>{
var val_out;
val_out = val_in * 10;
console.log(processName + '이 처리중입니다');
resolve(val_out);
})
}
댓글
댓글 쓰기