Created
February 19, 2023 08:51
-
-
Save nsulistiyawan/42a827acd3ac8541f1f2b0a5f698b89c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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