Last active
February 7, 2017 02:00
-
-
Save cristopher-rodrigues/b9bce06034c2336957ffd2f0e3001199 to your computer and use it in GitHub Desktop.
promisse callback hells each
This file contains 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
// test here: http://jsfiddle.net/6fjzyes5/ | |
const Bluebird = Promise.noConflict() | |
let merchant = {}; | |
let customer = {}; | |
let payment = {}; | |
let MerchantPromise = function () { | |
return new Promise(function (resolve, reject) { | |
setTimeout(function () { | |
console.log(MerchantPromise.name); | |
merchant = {name: "EBANX"}; | |
resolve(); | |
}, 1000) | |
}) | |
}; | |
var CustomerPromise = function () { | |
return new Promise(function (resolve, reject) { | |
setTimeout(function () { | |
console.log(CustomerPromise.name, merchant); | |
customer = {name: "Cristopher"}; | |
resolve(); | |
}, 50) | |
}) | |
}; | |
var PaymentPromise = function () { | |
return new Promise(function (resolve, reject) { | |
setTimeout(function () { | |
console.log(PaymentPromise.name, merchant, customer); | |
payment = {type: "visa"}; | |
resolve(); | |
}, 50) | |
}) | |
}; | |
Bluebird.each([MerchantPromise, CustomerPromise, PaymentPromise], function (promiseFn) { | |
return promiseFn(); | |
}, {concurrency: 1}) | |
.then(function() { | |
console.log(merchant, customer, payment); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment