Skip to content

Instantly share code, notes, and snippets.

@choru-k
Last active November 19, 2016 06:08
Show Gist options
  • Save choru-k/bbc08b8f217d50e72e4873dab056ed3f to your computer and use it in GitHub Desktop.
Save choru-k/bbc08b8f217d50e72e4873dab056ed3f to your computer and use it in GitHub Desktop.
promise chain test 1
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
@choru-k
Copy link
Author

choru-k commented Nov 19, 2016

then쪽의 콜백함수에 promise객체를 반환하지 않으므로 내부의 모든 async함수 실행하고 다음 then으로 이동

이게 잘 이해가 안되요

@choru-k
Copy link
Author

choru-k commented Nov 19, 2016

then의 return은 항상 promise객체로 변환되잖아요

@voidsatisfaction
Copy link

여기서 then뒤에는 아에 return 이 없잖아

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment