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