async function sleep(delay) {
return new Promise(resolve => {
setTimeout(resolve, delay)
})
}
async function foo(delay) {
const t0 = Date.now()
await sleep(delay)
console.log(Date.now() - t0);
}
foo(5000)//5006
js实现sleep
最新推荐文章于 2024-05-27 09:32:47 发布