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.
spawncreates a task-like handle.joinwaits 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.
sendappends a value to the channel.recvwaits 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.
allwaits for every future and preserves result order.racereturns 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.