Created
July 27, 2018 01:27
-
-
Save taketime/ab56a778b5d61d632ae3940ff4884812 to your computer and use it in GitHub Desktop.
Simple example
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 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