Created
August 28, 2022 16:21
-
-
Save gagan-bansal/958eb20d9e9616ed7f3c80659514c7f1 to your computer and use it in GitHub Desktop.
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
// https://stackoverflow.com/a/44330807/713573 | |
(async () => { | |
// sync function | |
function syncFunc (opts) { | |
return 'done'; | |
} | |
const asyncSyncFunc = async (params) => { | |
return syncFunc(params); | |
}; | |
const result = await asyncSyncFunc(); | |
console.log(result); | |
// sync function throws error | |
function buggySyncFunc (opts) { | |
throw new Error('Sync is buggy'); | |
} | |
const asyncBuggySyncFunc = async (params) => { | |
return buggySyncFunc(params); | |
}; | |
try { | |
const result = await asyncBuggySyncFunc(); | |
console.log('Should not execute.'); | |
} catch (error) { | |
console.log(error.message); | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment