Skip to content

Instantly share code, notes, and snippets.

@nsulistiyawan
Created February 19, 2023 08:53
Show Gist options
  • Save nsulistiyawan/d349db26943d9a3ae403bddfe2dee1de to your computer and use it in GitHub Desktop.
Save nsulistiyawan/d349db26943d9a3ae403bddfe2dee1de to your computer and use it in GitHub Desktop.
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