Created
March 13, 2019 11:21
-
-
Save amironov73/dfc968056bce78de4cd82792d612a810 to your computer and use it in GitHub Desktop.
JavaScript async/await
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 first() { | |
| console.log('First'); | |
| return 1; | |
| } | |
| async function second() { | |
| console.log('Second/1'); | |
| const result1 = await first(); | |
| console.log('Second/2'); | |
| return result1 + 1; | |
| } | |
| async function third() { | |
| console.log('Third/1'); | |
| const result2 = await second(); | |
| console.log('Third/2'); | |
| return result2 + 1; | |
| } | |
| (async () => { | |
| console.log('Top/1'); | |
| const result3 = await third(); | |
| console.log('Result is ' + result3); | |
| console.log('Top/2'); | |
| })().then(() => | |
| { | |
| console.log('Top/3'); | |
| }); | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prints:
Top/1
Third/1
Second/1
First
Second/2
Third/2
Result is 3
Top/2
Top/3