Created
March 12, 2017 18:43
-
-
Save mightyguava/bcc4d278bf88082e0a7aa1e477d9ca85 to your computer and use it in GitHub Desktop.
Demystifying Async Programming in Javascript - fetchJson promise fixed
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
fetchJson('/api/user/self') | |
.then(function (user) { | |
return fetchJson('/api/user/interests?userId=' + self.id) | |
.then(interests => { | |
user: user, | |
interests: interests | |
}); | |
}) | |
.then(function (blob) { | |
return Promise.all[blob.interests.map(i => fetchJson('/api/recommendations?topic=' + i))] | |
.then(recommendations => { | |
user: blob.user, | |
interests: blob.interests, | |
recommendations: recommendations | |
}); | |
}) | |
.then(function (bigBlob) { | |
render(bigBlob.user, bigBlob.interests, bigBlob.recommendations); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment