function sleep(time = 1000) {
return new Promise(resolve => {
let timer = setTimeout(() => {
clearTimeout(timer);
timer = null;
resolve(0);
}, time);
});
}
async function accomplishAsync() {
await sleep(3000);
console.log(1)
}
accomplishAsync();
基于 async 、await 实现的 sleep 函数
最新推荐文章于 2024-08-06 14:35:51 发布