Home / Docs / Guides

Concurrent tasks: together

Release v0.4.0

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

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