Skip to content

Instantly share code, notes, and snippets.

@taketime
Created July 27, 2018 01:27
Show Gist options
  • Save taketime/ab56a778b5d61d632ae3940ff4884812 to your computer and use it in GitHub Desktop.
Save taketime/ab56a778b5d61d632ae3940ff4884812 to your computer and use it in GitHub Desktop.
Simple example
async function someFunc() {
const somePromise = new Promise((resolve, reject) => {
resolve('cool ' + Math.random())
})
// return Promise.reject(new Error('bs!')) // Could reject
// throw new Error('yowza') // or could throw
return somePromise
}
someFunc().then((result) => {
console.log('promise with .then resolved to:', result)
}).catch(e => {
console.log('1st err:', e)
})
;(async () => {
try {
const result = await someFunc()
console.log('await resolved promise to:', result)
} catch (e) {
console.log('2nd err:', e)
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment