Created
February 19, 2023 08:55
-
-
Save nsulistiyawan/0247c3ef7cf8624ca96a1ad948deece4 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() { | |
// fire and await together | |
const [userResult, productResult, otherResult] = | |
await Promise.allSettled([ | |
fetchUser(), fetchProduct(), fetchOther() | |
]) | |
// process user | |
if (userResult.status === 'rejected') { | |
const err = userResult.reason | |
handleError(err) | |
} else { | |
const user = userResult.value | |
} | |
// process product | |
if (productResult.status === 'rejected') { | |
const err = productResult.reason | |
handleError(err) | |
} else { | |
const product = productResult.value | |
} | |
// process other | |
if (otherResult.status === 'rejected') { | |
const err = otherResult.reason | |
handleError(err) | |
} else { | |
const other = otherResult.value | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment