Created
October 10, 2017 18:13
-
-
Save bmorelli25/c4eb7dd7bc77356ca1c543769b2564f8 to your computer and use it in GitHub Desktop.
async function 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
| function resolveAfter2Seconds(x) { | |
| return new Promise(resolve => { | |
| setTimeout(() => { | |
| resolve(x); | |
| }, 2000); | |
| }); | |
| } | |
| async function add1(x) { | |
| const a = await resolveAfter2Seconds(20); | |
| const b = await resolveAfter2Seconds(30); | |
| return x + a + b; | |
| } | |
| add1(10).then(v => { | |
| console.log(v); | |
| }); | |
| // Source - MDN - https://goo.gl/1yfzKy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment