注意async函数中有return与没return是有区别的!!!(知道原因的同学可以留言解释一下!)
两种方法请自行尝试!
console.log('start');
async function async1(){
console.log('async1 start');
await async2()
console.log('async1 end');
}
async function async2(){
return new Promise(resolve => { // 有return和没return的区别
console.log('async2 promise');
resolve()
}).then(() => {
console.log('async2 promise then');
})
// console.log('async2 end');
}
setTimeout(() => {
console.log('setTimeout');
},0)
async1()
new Promise(resolve => {
console.log('Promise');
resolve()
}).then(() => {
console.log('promise then');
})
console.log('end');