1.await会执行promise的resolve的状态,相当于执行了then函数
async function a1(){
console.log("a1-start")
await a2();
console.log("a1-end")
}
async function a2(){
console.log("a2")
}
a1();
console.log("end-script")
await会将函数阻塞,会优先执行同步不耗时的任务
async function show(){
console.log("start");
await mid();
console.log("end")
}
async function mid(){
console.log("mid")
}
show()
console.log("line")
async function a1() {
console.log("a1-start")
await a2();
console.log("a1-end")
}
async function a2() {
console.log("a2")
}
a1();
console.log("end-script")
new Promise((resolve) => {
console.log("a3")
resolve()
}).then(() => {
console.log("a4")
})
await后面的代码可以看做是一个异步回调