async 函数返回的内容,会被自动包裹成一个Promise, await 不会阻塞主线程
async function f1(){
console.log('1 step')
let start = Date.now();
// while((Date.now() - start) < 1000*10){
// }
let dryResult = await dryWork()
console.log('3 step ')
return dryResult;
}
function dryWork(){
return new Promise((res,rej)=>{
setTimeout(()=>{
res('4 step')
},2000)
})
}
f1().then((result)=>{
console.log(result)
})
console.log('2 step ')