console.log( ‘script start’ )
async function async1() {
console.log( ‘async1 start’ )
await async2() // 这里不会阻塞,阻塞的是await async2后面的
console.log( ‘async1 end’ )
}
async function async2() {
console.log( ‘async2’ )
}
async1();
setTimeout( function () {
console.log( ‘setTimeout’ )
}, 0 )
new Promise( function ( resolve ) {
console.log( ‘promise’ )
resolve(1);
} ).then( function (res) {
console.log( ‘promise1’, res )
} ).then((res) => {
console.log( ‘promise2’, res )
})
console.log( ‘script end’ )
//
script start
async1 start
async2
promise
script end
async1 end
promise1 1
promise2 undefined
setTimeout