Last active
November 19, 2016 06:08
-
-
Save choru-k/bbc08b8f217d50e72e4873dab056ed3f to your computer and use it in GitHub Desktop.
promise chain test 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _promise1 = function (param) { | |
return new Promise(function (resolve, reject) { | |
setTimeout(function () { | |
resolve("ok1"); | |
}, 3000); | |
}); | |
}; | |
var _promise2 = function (param) { | |
return new Promise(function (resolve, reject) { | |
setTimeout(function () { | |
resolve("ok2"); | |
}, 3000); | |
}); | |
}; | |
_promise1(true) | |
.then(function (text) { | |
_promise2(true) | |
.then(function (text) { | |
console.log(text); | |
}) | |
console.log(text); | |
}).then(function() { | |
console.log('ok3') | |
}); | |
// result | |
// ok1 - 3second later | |
// ok3 - 3second later | |
// ok2 - 6second later |
then쪽의 콜백함수에 promise객체를 반환하지 않으므로 내부의 모든 async함수 실행하고 다음 then으로 이동
이게 잘 이해가 안되요
then의 return은 항상 promise객체로 변환되잖아요
여기서 then뒤에는 아에 return 이 없잖아
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
_promise1
실행(그 안의 async함수들은 async하게 실행된다.)console.log('ok3')
실행_promise2(true)
이 함수의 resolve가 호출되고console.log('ok2')
실행즉, 위의 코드는
이거랑 다를바가 없다.