async function async1() {
console.log('async1 start');
await async2();
console.log('async1 end');
}
async function async2() {
console.log('async2 start');
return new Promise((resolve, reject) => {
resolve();
console.log('async2 promise');
})
}
async1();
new Promise(function(resolve) {
console.log('promise1');
resolve();
}).then(function() {
console.log('promise2');
}).then(function() {
console.log('promise3');
});
为什么输出顺序如下
async1 start
async2 start
async2 promise
promise1
promise2
promise3
async1 end
主要困惑是 async1 end
为什么在 promise3
后面?
async1函数可以转化成下面这样
具体的分析这里有:https://segmentfault.com/q/10...