---
title: "Concurrent tasks: together"
url: https://una-lang.org/en/docs/guides/concurrency/
release: v0.4.0
source: https://github.com/una-lang/una/blob/v0.4.0/docs/guide/una-for-agents.md
---

# Concurrent tasks: together

`together` runs independent work at once with the result and trace of a sequential run (`spec/19`).

- A `together` statement holds two or more `let` branches (U2024 otherwise). Each branch runs as a task, sees the bindings before the block but not its siblings, and its binding is in scope after the block. Each branch's handling clauses stand on their own lines, as for any `let`.
- `let ys = together for x in xs` runs its indented body once per element, or per integer of a range, and builds the list of results in order.
- A task cannot assign, `edit` or `take` a binding declared outside it (U2023): return new values instead. Tasks use the capabilities of the enclosing function, and a parameter named by `uses of` or `fails of`.
- When a task fails, the tasks after it are canceled, and the block fails with the failure of the first task that failed: the outcome of running the tasks one after another.
- The trace lists each task's events in task order, with the task's path, as `"task": "2"`; the order in which tasks really performed effects, such as the lines they print, may differ.

```una
module demo

pub kind ReadError = | Unreachable

pub capability Sensor
  op reading() -> Int
    fails ReadError

pub warmest() -> Int
  uses @north: Sensor[reading]
  uses @south: Sensor[reading]
  fails ReadError
=
  together
    let n = @north.reading()
      if error pass
    let s = @south.reading()
      if error pass
  max(n, b: s)

pub squares(n: Int) -> List[Int]
=
  let squares = together for i in 0..<n
    i * i
  squares
```

```una
-- fails with U2023
module demo

pub count(xs: List[Int]) -> Int
=
  let edit seen = 0
  let doubled = together for x in xs
    seen = seen + 1
    x * 2
  seen
```
