手写一个sleep函数

async function async1(){
await async2(2000)
//2秒后返回一个1
console.log(1);
}
function async2(timeout){
return new Promise((resolve,reject)=>{
setTimeout(() => {
resolve()
}, timeout);
})
}
async1()

posted @ 2022-09-26 14:30  Judy倩倩  阅读(36)  评论(0)    收藏  举报