Forked from MikeBild/async-await-promise-all-error-handling.js
Created
May 10, 2018 23:07
-
-
Save AlexZeitler/07824eed41e858a55dc7b99d035101cf to your computer and use it in GitHub Desktop.
Avoid async/await on integration level
This file contains 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
const defaultFirst = 'A`' | |
const defaultSecond = 'B`' | |
const defaultThird = 'C`' | |
async function doFirst() { | |
// throw new Error('Error A') | |
return await 'A' | |
} | |
async function doSecond() { | |
//throw new Error('Error B') | |
return await 'B' | |
} | |
function doThirdSync() { | |
//throw new Error('Error C') | |
return 'C' | |
} | |
async function doThird() { | |
//throw new Error('Error C') | |
return new Promise(resolve => resolve(doThirdSync())) | |
} | |
(async () => { | |
const result = await Promise.all([ | |
doFirst().catch(() => defaultFirst), | |
doSecond().catch(() => defaultSecond), | |
doThird().catch(() => defaultThird), | |
]) | |
console.log(result) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment