Skip to content

Instantly share code, notes, and snippets.

@copperwall
Last active June 11, 2019 03:33
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 copperwall/093fe7758398643e532c0fa246001c77 to your computer and use it in GitHub Desktop.
Save copperwall/093fe7758398643e532c0fa246001c77 to your computer and use it in GitHub Desktop.
function getGuides() {
let ids = [...Array(10).keys()];
return ids.reduce((accumulator, id) => {
return accumulator.then(results => {
return fetch(id).then(result => {
results.push(result);
return results;
});
});
}, Promise.resolve([]));
for (let i = 1; i <= 10; i++) {
let res = await fetch(`/api/2.0/guides/${i}`);
results.push(res);
}
return results;
}
getGuides().then(guides => console.log(guides));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment