Created
May 20, 2021 17:52
-
-
Save amcsi/10b5edb5576b16afe5ad3864ea2c08e1 to your computer and use it in GitHub Desktop.
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
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