Skip to content

Commit

Permalink
refine docs
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Dec 1, 2024
1 parent d529634 commit d6cff01
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions docs/async/timeout.mdx
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
---
title: timeout
description: Asynchronously rejects after a specified amount of time.
description: Create a promise that rejects after some time
since: 12.3.0
---

### Usage

The `_.timeout` function creates a promise that will reject after a given number of milliseconds. You can provide a custom error message or a function that returns an error to be thrown upon rejection.
The `timeout` function creates a promise that rejects after a specified delay, with an optional custom error message or error function.

The default error is a `TimeoutError` with the message "Operation timed out".

```ts
import * as _ from 'radashi'

// Rejects after 1 second with the default "timeout" error message
// Rejects after 1 second with a default TimeoutError
await _.timeout(1000)

// Rejects after 1 second with a custom error message
// Rejects after 1 second with a custom TimeoutError message
await _.timeout(1000, 'Custom timeout message')

// Rejects after 1 second with a custom error object
// Rejects after 1 second with a custom error type
await _.timeout(1000, () => new Error('Custom error'))
```

Expand Down

0 comments on commit d6cff01

Please sign in to comment.