JS异步--微队列宏队列

192 阅读1分钟

写出下面代码的执行顺序

async function async1() {
console.log('async1 start')
await async2()
// console.log('async1 end')
new Promise((resolve, reject) => {
  console.log('await后接的promise')
  resolve()
}).then(res => {
  console.log('await后接的promise .then')
})
}
async function async2() {
console.log('async2 end')
}

setTimeout(() => {
console.log('setTimeout')
})
async1()

console.log('script start')

new Promise((resolve, reject) => {
console.log('promise start')
resolve()
}).then(res => {
console.log('promise1')
}).then(res => {
console.log('promise2')
})

new Promise((resolve, reject) => {
console.log('promise start')
resolve()
}).then(res => {
console.log('是不是会插入在他前面呢')
})

console.log('script end')