Skip to content

Instantly share code, notes, and snippets.

@g6ling
Created November 18, 2016 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save g6ling/96980fb868f4aacee554d9eb7a642532 to your computer and use it in GitHub Desktop.
Save g6ling/96980fb868f4aacee554d9eb7a642532 to your computer and use it in GitHub Desktop.
var _promise1 = function (param) {
return new Promise(function (resolve, reject) {
setTimeout(function () {
console.log('ok1');
resolve(param);
}, 100);
});
};
var _promise2 = function (param) {
return new Promise(function (resolve, reject) {
setTimeout(function () {
console.log('ok2');
resolve(param);
}, 100);
});
};
var _promise3 = function (param) {
return new Promise(function (resolve, reject) {
setTimeout(function () {
console.log('ok3');
resolve(param);
}, 100);
});
};
var func4 = function(param) {
console.log('ok4');
return _promise3(param);
}
var param = true;
_promise1(param)
.then(function (param) {
if (param) {
return _promise2(param)
} return func4(param)
}).then(function() {
console.log('ok5')
});
// param === true
// Result
// ok1
// ok2
// ok5
// param === false
// Result
// ok1
// ok4
// ok3
// ok5
@voidsatisfaction
Copy link

ok

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