Skip to content

Instantly share code, notes, and snippets.

@gagan-bansal
Created August 28, 2022 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gagan-bansal/958eb20d9e9616ed7f3c80659514c7f1 to your computer and use it in GitHub Desktop.
Save gagan-bansal/958eb20d9e9616ed7f3c80659514c7f1 to your computer and use it in GitHub Desktop.
// 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