Concurrency
Aria provides colorless concurrency with lightweight tasks, channels, and mutexes. There is no async/await coloring — a function that spawns tasks looks identical to one that doesn't.
Spawning Tasks
// Spawn a task
task := spawn fetchData(url)
// Wait for the result
result := task.await() Channels
Channels provide typed communication between tasks:
// Create a channel
ch := chan[str]()
// Send and receive
spawn fn() {
ch.send("hello from task")
}()
msg := ch.recv()
println(msg) // "hello from task" Mutexes
Protect shared state with mutexes:
mutex := Mutex.new(0)
scope {
for i in 0..10 {
spawn fn() {
mutex.lock()
// critical section
mutex.unlock()
}()
}
} Concurrency Bounds
Types that cross task boundaries must implement Send and Share. These are automatically derived for primitive types:
// Send: can be moved to another task
// Share: can be accessed from multiple tasks
fn spawnWorker[T: Send](data: T) {
spawn processData(data)
} Colorless
Unlike Rust's async/await or C++'s co_await, Aria's concurrency has no function coloring. A function that spawns tasks looks identical to one that doesn't — no async keyword, no special return types.
Planned Features
The following concurrency features are specified but not yet implemented:
- Structured
scope { }blocks — automatic join of all spawned tasks when the scope exits selectexpression — wait on multiple channels simultaneouslyspawn.detach— fire-and-forget background tasks- Directional channels —
chan.Send[T]andchan.Recv[T] - Channel iteration —
for msg in channel { } - Cancellation tokens — cooperative task cancellation
- Additional primitives —
RWMutex,Atomic,WaitGroup,Once,Barrier