Open ForeveHG opened 4 years ago
比如sleep(1000)意味着等待1000毫秒,可以从Promise,Generator,Async/await等角度
循环阻塞主线程,真正意义上的sleep
定时器
Promise+定时器
function sleep(delay) { return new Promise(resolve => { setTimeout(resolve,delay) }) }
async + Promise + 定时器
比如sleep(1000)意味着等待1000毫秒,可以从Promise,Generator,Async/await等角度