Created
January 17, 2018 09:56
-
-
Save maxleiko/2e19c241bf06fe5cfec89e1c91ae7faf to your computer and use it in GitHub Desktop.
ES6 async/await example
This file contains hidden or 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 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