Skip to content

Instantly share code, notes, and snippets.

@mightyguava
Created March 12, 2017 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mightyguava/3646f493dbc8e5fc0d24b2ce2545f885 to your computer and use it in GitHub Desktop.
Save mightyguava/3646f493dbc8e5fc0d24b2ce2545f885 to your computer and use it in GitHub Desktop.
Demystifying Async Programming in Javascript - fetchJson promise
fetchJson('/api/user/self')
.then(function (user) {
return fetchJson('/api/user/interests?userId=' + self.id);
})
.then(function (interests) {
return Promise.all[interests.map(i => fetchJson('/api/recommendations?topic=' + i))];
})
.then(function (recommendations) {
render(user, interests, recommendations);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment