Last active
August 29, 2015 14:21
-
-
Save nathggns/efaf6797c89895f1a66f to your computer and use it in GitHub Desktop.
Demonstration of some cool es7 features.
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
require('babel/polyfill'); | |
/** | |
* Imagine this is some complex async process | |
*/ | |
async function random() { | |
return new Promise(r => r(Math.random())); | |
} | |
async function main() { | |
try { | |
console.log(Math.floor(await random() * 1000)); | |
} catch (e) { | |
console.error(e); | |
} | |
} | |
main(); | |
/** CAN ALSO BE WRITTEN AS */ | |
require('babel/polyfill'); | |
/** | |
* Imagine this is some complex async process | |
*/ | |
async function random() { | |
return new Promise(r => r(Math.random())); | |
} | |
async function main() { | |
return Math.floor(await random() * 1000); | |
} | |
main().then(::console.log).catch(::console.error); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment