Last active
April 7, 2017 21:19
-
-
Save TravisMullen/eeb49986276c234ad8c76d591bf2af58 to your computer and use it in GitHub Desktop.
Multiple Promises
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
// | |
// https://developers.google.com/web/fundamentals/getting-started/primers/promises | |
// | |
// With Promises | |
let dis = this | |
return new Promise(function (resolve, reject) { | |
return this.promises.reduce(function (chain, individualPromise) { | |
return chain.then(function () { | |
return individualPromise | |
}).then(function (value) { | |
dis.activeExchanges.push(value) | |
}) | |
}, Promise.resolve()) | |
}).then(function () { | |
console.log('All done') | |
}).catch(function (err) { | |
console.log('err', err) | |
// catch any error that happened along the way | |
// addTextToPage("Argh, broken: " + err.message) | |
}).then(function () { | |
// finally | |
dis.loading = false | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment