先看两个示例体现的问题
async function async1() {
console.log("2");
await async2();
console.log(23132);
await async3();
console.log("3");
}
async function async2() {
console.log("4");
await async4();
}
async function async3() {
console.log("5");
}
async function async4() {
console.log("6");
}
async1();
setTimeout(function () {
console.log("setTimeout");
}, 0);
new Promise((resolve) => {
console.log("Promise");
resolve();
})
.then(function () {
console.log("promise1");
})
.then(function () {
console.log("promise2");
});
console.log("7");
结果//
2
4
6
Promise
7
promise1
23132
5
promise2
3
setTimeout
async function async1() {
console.log("2");
await async2();
console.log(23132);
await async3();
console.log("3");
}
async function async2() {
console.log("4");
// await asy