# Module /thread

OS thread spawning, parallel execution, sleeping, and synchronization.

```tangu
(use /thread)
```

## Functions & symbols

### await

`(await handle) -> Any`

Blocks until the spawned OS thread completes and returns its result.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `handle` | `Thread-Future` | no | Thread handle returned by `thread/spawn` |

```tangu
(let out (thread/await h))
```

### await-all

`(await-all handles) -> Array`

Waits for all OS threads in `handles` and collects results in order.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `handles` | `Array` | no | Array of Thread-Future handles |

```tangu
(let results (thread/await-all [h1 h2]))
```

### sleep

`(sleep duration-ms) -> None`

Sleeps the current OS thread for `duration-ms` milliseconds.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `duration_ms` | `Int | Float` | no | Milliseconds to sleep |

```tangu
(thread/sleep 250)
```

### spawn

`(spawn func) -> Thread-Future`

Spawns an OS thread running `func` and returns a `Thread-Future` handle.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `func` | `Func` | no | Zero-argument closure to run on a dedicated OS thread |

```tangu
(let h (thread/spawn (Func () (heavy-compute))))
```
