Skip to content

Instantly share code, notes, and snippets.

@nsulistiyawan
Created February 19, 2023 08:51
Show Gist options
  • Save nsulistiyawan/42a827acd3ac8541f1f2b0a5f698b89c to your computer and use it in GitHub Desktop.
Save nsulistiyawan/42a827acd3ac8541f1f2b0a5f698b89c to your computer and use it in GitHub Desktop.
async function loadInitialData() {
const userPromise = fetchUser();
const productPromise = fetchProduct();
const otherPromise = fetchOther();
// all of them running simultaneously
try {
const user = await userPromise;
} catch (error) {
console.log(error)
}
try {
const product = await productPromise;
} catch (error) {
console.log(error)
}
try {
const other = await otherPromise;
} catch (error) {
console.log(error)
}
}
//fetchUser + fetchProduct + fetchOther = 600ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment