Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Demystifying Async Programming in Javascript - fetchJson promise fixed
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
You can’t perform that action at this time.