队列的执行顺序

<script>
console.log("script start");
async function async1(){
await async2();
console.log("async1 end");
}
async function async2(){
console.log("async2 end");
}
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("script end");

/*
script start
async2 end
Promise
script end
async1 end
Promise1
Promise2
setTimeout

*/
/*
先执行微任务,在执行宏任务
wait会阻塞async1后面的代码执行,所以先跳出来继续执行后面的代码。
微任务:then()
宏任务:setTimeout
*/
</script>
posted @ 2019-12-20 14:17  倔强的代码人  阅读(446)  评论(0编辑  收藏  举报