延迟执行函数,可选的异步回调 Delays execution with optional asynchronous callback
延迟的毫秒数 / Delay time in milliseconds
Optional
可选的回调函数,将在延迟后执行 / Optional callback function to execute after delay
延迟完成后解析的Promise / Promise that resolves after the delay
// 等待1秒后执行// Wait for 1 second then executeawait sleep(1000) Copy
// 等待1秒后执行// Wait for 1 second then executeawait sleep(1000)
// 等待1秒后执行回调函数// Wait for 1 second then execute callbackawait sleep(1000, () => console.log('Done')) Copy
// 等待1秒后执行回调函数// Wait for 1 second then execute callbackawait sleep(1000, () => console.log('Done'))
延迟执行函数,可选的异步回调 Delays execution with optional asynchronous callback