| 1 | --- |
| 2 | title: "htmx.timeout()" |
| 3 | description: "Create a timeout promise" |
| 4 | --- |
| 5 | |
| 6 | The `htmx.timeout()` function creates a promise that resolves after a specified time interval. |
| 7 | |
| 8 | ## Syntax |
| 9 | |
| 10 | ```javascript |
| 11 | await htmx.timeout(time) |
| 12 | ``` |
| 13 | |
| 14 | ## Parameters |
| 15 | |
| 16 | - `time` - Time to wait (number in ms or string like "2s", "500ms") |
| 17 | |
| 18 | ## Example |
| 19 | |
| 20 | ```javascript |
| 21 | // Wait 2 seconds |
| 22 | await htmx.timeout("2s"); |
| 23 | console.log("2 seconds passed"); |
| 24 | |
| 25 | // Wait 1000ms |
| 26 | await htmx.timeout(1000); |
| 27 | console.log("1 second passed"); |
| 28 | ``` |
| 29 | |
| 30 | ## Return Value |
| 31 | |
| 32 | Returns a Promise that resolves after the specified time. If time is 0 or negative, resolves immediately. |