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. / 超时的毫秒数
A promise that rejects with a TimeoutError after the specified delay. / 一个 promise,它将在指定的延迟时间后拒绝,抛出一个 TimeoutError。
Throws a TimeoutError after the specified delay. / 在指定的延迟时间后抛出 TimeoutError。
try { await timeout(1000); // Timeout exception after 1 second} catch (error) { console.error(error); // Will log 'The operation was timed out'} Copy
try { await timeout(1000); // Timeout exception after 1 second} catch (error) { console.error(error); // Will log 'The operation was timed out'}
Returns a promise that rejects with a
TimeoutErrorafter a specified delay.返回一个 promise,该 promise 在指定的延迟时间后拒绝,抛出一个
TimeoutError。