mirror of
https://github.com/toss/es-toolkit.git
synced 2024-11-28 03:34:26 +03:00
570 B
570 B
timeout
Returns a Promise
that rejects with a TimeoutError
after the specified timeout.
Signature
function timeout(ms: number): Promise<never>;
Parameters
ms
(number
): The number of milliseconds for the promise to reject withTimeoutError
.
Returns
(Promise<never>
): A Promise that rejects after the specified timeout.
Examples
Basic Usage
try {
await timeout(1000); // Timeout exception after 1 second
} catch (error) {
console.error(error); // Will log 'The operation was timed out'
}