Created
November 26, 2017 08:26
-
-
Save dgeibi/374aa79d83057cdcf12012708d38dbae to your computer and use it in GitHub Desktop.
async promise timer
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 async1() { | |
| console.log('async 1') | |
| await async2() | |
| await async3() | |
| console.log('async 1-1') | |
| } | |
| async function async2() { | |
| console.log('async 2') | |
| } | |
| async function async3() { | |
| console.log('async 3') | |
| } | |
| async1() | |
| setTimeout(() => { | |
| console.log('timeout') | |
| }, 0) | |
| new Promise((res) => { | |
| console.log('promise') | |
| res() | |
| }).then(() => { | |
| console.log('promise then') | |
| }) | |
| console.log('1') | |
| /** | |
| * 执行async fn, async function的第一个await及之前的代码同步执行 | |
| async 1 | |
| async 2 | |
| promise | |
| 1 | |
| async 3 | |
| promise then | |
| async 1-1 | |
| timeout | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment