Skip to content

Instantly share code, notes, and snippets.

@TravisMullen
Last active April 7, 2017 21:19
Show Gist options
  • Save TravisMullen/eeb49986276c234ad8c76d591bf2af58 to your computer and use it in GitHub Desktop.
Save TravisMullen/eeb49986276c234ad8c76d591bf2af58 to your computer and use it in GitHub Desktop.
Multiple Promises
//
// 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