Skip to content

Instantly share code, notes, and snippets.

@nathggns
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathggns/efaf6797c89895f1a66f to your computer and use it in GitHub Desktop.
Save nathggns/efaf6797c89895f1a66f to your computer and use it in GitHub Desktop.
Demonstration of some cool es7 features.
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