Last active
October 10, 2024 05:51
-
-
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
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
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