Skip to content

Instantly share code, notes, and snippets.

@MikeBild
Last active May 10, 2018 23:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save MikeBild/784496f7504c7d790ab28b53a2463641 to your computer and use it in GitHub Desktop.
Save MikeBild/784496f7504c7d790ab28b53a2463641 to your computer and use it in GitHub Desktop.
Avoid async/await on integration level
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