zhuanghaixin / Interview

8 stars 0 forks source link

Sleep函数 #223

Open zhuanghaixin opened 2 years ago

zhuanghaixin commented 2 years ago
async function sleep(delay) {

    return new Promise((resolve)=>setTimeout(resolve,delay))
}
async function foo(){
    const t0 = Date.now()
    await sleep(1500)
    console.log(Date.now()-t0)
}
foo()