Skip to content
La3 Docs
Browse docs

Concurrency

Cooperative interpreter tasks, channels, spawn, join, await all, and race.

Execution model

The interpreter models concurrency cooperatively, while the language surface keeps room for real parallelism.

The current interpreter runs tasks cooperatively. A spawned task runs when something needs its result, when a receiver blocks, or when program shutdown drains fire-and-forget work. This gives useful task interleaving without pretending the interpreter is preemptive.

  • spawn creates a task-like handle.
  • join waits for the result.
  • Blocked channel receives can drive scheduled producers.
  • Deadlock is reported when no runnable task can fill or close a channel.

Channels

Channels move values between tasks without sharing mutable memory directly.

  • send appends a value to the channel.
  • recv waits for a value or channel close.
  • Iterating a channel reads until close.
  • Capacity is advisory in the cooperative interpreter.
let ch = channel<str>(capacity: 32)

spawn {
    ch.send("ready")
    ch.close()
}

for msg in ch {
    io.println(msg)
}

Async helpers

await all and await race name the two most common multi-future patterns.

  • all waits for every future and preserves result order.
  • race returns the first completed result.
  • Timeouts are naturally expressed as a race between work and sleep.
  • Docs should state whether a concurrency example is about interleaving or actual parallel CPU work.