JavaScript/sleep
来自康健生活
引用
模拟
function sleep (time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
sleep(500).then(() => {
// ...
})
同步执行
function sleep (time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
(async function() {
console.log('Do some thing, ' + new Date());
await sleep(3000);
console.log('Do other things, ' + new Date());
})();
(来源摘自互联网示例,作者 未知)
No categories