ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 프로마이스 연습
    자바스크립트 2019. 1. 18. 09:30
    doSomething()
    .then( result => doSomethingElse(result) )
    .then(newResult => doThirdThing(newResult))
    .then(finalResult => { console.log(`Got the final result: ${finalResult}`); })
    .catch(failureCallback);


    function doSomething(){
    return new Promise(function(resolve,reject){

    setTimeout(function() {
    console.log('doSomething');

    resolve('result1');
    }, 1000);
    })

    }

    function doSomethingElse(){

    return new Promise(function(resolve,reject){

    setTimeout(function() {
    console.log('doSomethingElse');

    resolve('result2');
    }, 1000);
    })


    }

    function doThirdThing(){

    return new Promise(function(resolve,reject){

    setTimeout(function() {
    console.log('doThirdThing');
    resolve('result3');
    }, 1000);
    })


    }


    function failureCallback(){

    console.log('call last call');

    }


    결과

    doSomething

    doSomethingElse

    doThirdThing

    Got the final result: result3

    '자바스크립트' 카테고리의 다른 글

    프로마이스  (0) 2019.01.18
    express-generator사용법  (0) 2018.10.10
Designed by Tistory.