Skip to content

Instantly share code, notes, and snippets.

@amcsi
Created May 20, 2021 17:52
Show Gist options
  • Save amcsi/10b5edb5576b16afe5ad3864ea2c08e1 to your computer and use it in GitHub Desktop.
Save amcsi/10b5edb5576b16afe5ad3864ea2c08e1 to your computer and use it in GitHub Desktop.
async function lol() {
const responseBodies = await Promise.all([
fetch('http://example.com/1').then(response => response.json()),
fetch('http://example.com/2').then(response => response.json()),
]);
return {
list: responseBodies[0],
template_something: responseBodies[1],
}
}
async function lol2() {
const responsePromises = [
fetch('http://example.com/1'),
fetch('http://example.com/2'),
];
// [Promise, Promise]
const responses = await Promise.all(responsePromises);
// [Response, Response]
const responseBodyPromises = responses.map(response => response.json());
// [Promise, Promise]
const responseBodies = await Promise.all(responseBodyPromises);
// [ResponseBody, ResponseBody];
return {
list: responseBodies[0],
template_something: responseBodies[1],
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment