sleep是一种函数,作用是延时,程序暂停若干时间。在执行时可能会抛出一个中断异常,建议对其进行捕获并处理。
sleep is a function that delays the program for a certain period of time. It may throw an interruption exception during execution, and it is recommended to catch and handle it.
延迟时间,单位为毫秒。
The delay time in milliseconds.
延迟指定毫秒后返回一个resolve的Promise对象。
Returns a resolved Promise after a specified number of milliseconds.
延迟的毫秒数。
The number of milliseconds to delay.
一个Promise,在指定的毫秒数后resolve。
A Promise that resolves after the specified number of milliseconds.
async function example() { console.log('start'); await sleep(1000); console.log('end');} Copy
async function example() { console.log('start'); await sleep(1000); console.log('end');}
延迟指定毫秒后返回一个 resolve 的 Promise 对象。
Returns a Promise that resolves after a specified number of milliseconds.
一个 Promise,在指定的毫秒数后 resolve。
// 返回Promise,有两种基本用法// #1sleep(1000).then(() => { console.log('这句话将在一秒后输出。')})// #2(async () => { await sleep(1000); console.log('这句话将在一秒后输出。')})(); Copy
// 返回Promise,有两种基本用法// #1sleep(1000).then(() => { console.log('这句话将在一秒后输出。')})// #2(async () => { await sleep(1000); console.log('这句话将在一秒后输出。')})();
Zh
sleep是一种函数,作用是延时,程序暂停若干时间。在执行时可能会抛出一个中断异常,建议对其进行捕获并处理。
En
sleep is a function that delays the program for a certain period of time. It may throw an interruption exception during execution, and it is recommended to catch and handle it.
Zh
延迟时间,单位为毫秒。
En
The delay time in milliseconds.