Created
December 7, 2016 00:24
-
-
Save kevinwucodes/52c1364b362d65186946e7a5f50ce82f to your computer and use it in GitHub Desktop.
async await sandbox
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
const prom = () => new Promise((resolve, reject) => { | |
setTimeout(() => { | |
reject('got rejected') | |
}, 2000) | |
}) | |
const foo = async () => { | |
try { | |
console.log('good', await prom()) | |
} catch(err) { | |
console.log('error', err); | |
} | |
} | |
foo() | |
// error got rejected (after 2 seconds) |
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
const prom = () => new Promise((resolve, reject) => { | |
setTimeout(() => { | |
resolve('got resolved') | |
}, 2000) | |
}) | |
const foo = async () => { | |
try { | |
console.log('good', await prom()) | |
} catch(err) { | |
console.log('error', err); | |
} | |
} | |
foo() | |
// good got resolved (after 2 seconds) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment