Last active
May 10, 2018 23:07
-
-
Save MikeBild/784496f7504c7d790ab28b53a2463641 to your computer and use it in GitHub Desktop.
Avoid async/await on integration level
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
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