Skip to content

Instantly share code, notes, and snippets.

@maxleiko
Created January 17, 2018 09:56
Show Gist options
  • Save maxleiko/2e19c241bf06fe5cfec89e1c91ae7faf to your computer and use it in GitHub Desktop.
Save maxleiko/2e19c241bf06fe5cfec89e1c91ae7faf to your computer and use it in GitHub Desktop.
ES6 async/await example
async function main() {
async function asyncJob() {
return new Promise((resolve) => {
// something async that will resolve in 1000ms
setTimeout(() => {
resolve(42);
}, 1000);
});
}
const result = await asyncJob();
console.log(result); // 42
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment