Skip to content

Instantly share code, notes, and snippets.

@kirilkirkov
Last active October 10, 2024 05:51
Show Gist options
  • Save kirilkirkov/cb2b80b4958bf4897e47d06d3ab5ba03 to your computer and use it in GitHub Desktop.
Save kirilkirkov/cb2b80b4958bf4897e47d06d3ab5ba03 to your computer and use it in GitHub Desktop.
Explain Promises with Async/Await and new Promise constructor. How to handle reject with Await keyword
async function getResp() {
try {
const authors = await getPromise(true);
console.log(authors, 'Try')
} catch(e) {
console.log(e, 'Catch')
}
}
function getPromise(resolveIt) {
return new Promise((resove, reject) => {
if(resolveIt) {
resove('ok, resove')
} else {
reject('not ok, reject')
}
})
}
getResp() // showed second
console.log(1) // showed first
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment