Created
February 19, 2023 08:53
-
-
Save nsulistiyawan/d349db26943d9a3ae403bddfe2dee1de 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
function onReject(err) { | |
return err | |
} | |
async function loadInitialData() { | |
//fire and await together | |
const [user, product, other] = await Promise.all([ | |
fetchUser().catch(onReject), | |
fetchProduct().catch(onReject) | |
fetchOther().catch(onReject) | |
]) | |
if (user instanceof Error) { | |
handleError(user) | |
} | |
if (product instanceof Error) { | |
handleError(product) | |
} | |
if (other instanceof Error) { | |
handleError(product) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment