//基本用法的async函数
let asyncFun = async function() {
return 1;
}
console.log(asyncFun());
//使用场景
//摇色字方法
function dice() {
return new Promise((resolve,reject)=>{
let sino = parseInt(Math.random()*6+1);
setTimeout(()=>{
resolve(sino);
},2000);
});
}
//异步方法
async function text() {
let n = await dice();
//await关键字后面调用摇色子方法执行完毕之后,才进行变量赋值
console.log("摇出来"+n);
}
text();