我的理解:async是异步的意思,在函数前面加async就是异步的异步,就成同步了,因为js函数本身就是异步的。而await就是使async函数实现异步的标志。
function one(){
return "one"
}
function two(){
return new Promise((resolve, reject)=>{
setTimeout(()=>{
resolve("two")
},3000)
})
}
function three(){
return "three"
}
async function run(){
console.log(one()) //马上输出"one"
console.log(await two()) //3秒后输入"two"
console.log(three()) //"two"输出后输出"three"
}
run()