# Module /coro

Cooperative coroutines (spawn, await, await-all, sleep) and typed channels (channel, send, recv) backed by Tokio.

```tangu
(use /coro)
```

## Functions & symbols

### await

`(coro/await future) -> Any`

Awaits an async coroutine or runtime future inside `*runtime*` and returns its resolved value.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `future` | `Coro-Future` | no | Coroutine or async future handle |

```tangu
(let res (coro/await fut))
```

### await-all

`(coro/await-all futures) -> Array`

Concurrently awaits all futures in `futures`, returning their results in order.

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

```tangu
(let all (coro/await-all [f1 f2]))
```

### channel

`(coro/channel) -> Channel`

Creates an async FIFO communication channel.

### recv

`(coro/recv channel) -> Any`

Receives a message from channel, yielding execution until one is available.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `channel` | `Channel` | no | Channel to read from |

### send

`(coro/send channel message) -> ()`

Sends a value into the channel.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `channel` | `Channel` | no | Target channel |
| `message` | `Any` | no | Value to transmit |

### sleep

`(coro/sleep millis) -> None`

Non-blocking async sleep suspending the current task for `millis` milliseconds.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `millis` | `Int | Float` | no | Milliseconds to yield |

```tangu
(coro/sleep 50)
```

### spawn

`(coro/spawn (Func () ...)) -> Coro-Future`

Spawns a non-blocking asynchronous coroutine task returning a `Coro-Future` handle.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `fn` | `Func` | no | Zero-argument task function |

```tangu
(let fut (coro/spawn (Func () (+ 20 22))))
```
