Skip to content

Instantly share code, notes, and snippets.

@dgeibi
Created November 26, 2017 08:26
Show Gist options
  • Select an option

  • Save dgeibi/374aa79d83057cdcf12012708d38dbae to your computer and use it in GitHub Desktop.

Select an option

Save dgeibi/374aa79d83057cdcf12012708d38dbae to your computer and use it in GitHub Desktop.
async promise timer
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