Returns a promise that rejects with a TimeoutError after a specified delay.
TimeoutError
返回一个 promise,该 promise 在指定的延迟时间后拒绝,抛出一个 TimeoutError。
the number of milliseconds to wait before rejecting the promise. 超时的毫秒数
Throws a TimeoutError after the specified delay.
@example Copy
@example
try { await timeout(1000); // Timeout exception after 1 second } catch (error) { console.error(error); // Will log 'The operation was timed out' }
Copy
Returns a promise that rejects with a
TimeoutErrorafter a specified delay.返回一个 promise,该 promise 在指定的延迟时间后拒绝,抛出一个
TimeoutError。