一个关于async+await+promise的问题。
javascript吧
全部回复
仅看楼主
level 8
执行到3的时候,为什么会调到promise里面去,而不是执行上面的6
async function async1() {//执行顺序
console.log('async1 start')//2
await async2()
console.log('async1 end')//6
}
async function async2() {
console.log('async2')//3
}
console.log('script start')//1
setTimeout(function () {
console.log('setTimeout')//8
}, 0)
async1();
new Promise(function (resolve) {
console.log('promise1')//4
resolve()
}).then(function () {
console.log('promise2')//7
})
console.log('script end')//5
2023年04月20日 05点04分 1
level 8
执行结果是这样的:
上面的写错了
script start
async1 start
async2
promise1
script end
promise2
async1 end
setTimeout
2023年04月20日 05点04分 2
1