Concurrency

Aria provides structured, colorless concurrency. Tasks are lightweight, scoped — they cannot leak, and errors propagate automatically. There is no async/await coloring.

Spawning Tasks

// Spawn a task
task := spawn fetchData(url)

// Wait for the result
result := task.await()

Structured Concurrency with Scopes

The scope block guarantees all spawned tasks complete before the scope exits:

scope {
    a := spawn fetchUsers()
    b := spawn fetchOrders()
    c := spawn fetchInventory()
}
// ALL three tasks are guaranteed complete here.
// No leaks. No forgotten joins.

If any task fails, the error propagates to the scope. Compare to Go:

// Go: goroutines can leak, errors silently drop
go fetchUsers()   // leaked if main exits
go fetchOrders()  // error goes nowhere

// Aria: impossible to leak, errors propagate
scope {
    spawn fetchUsers()   // error bubbles up
    spawn fetchOrders()  // scope waits for all
}

Channels

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)

// Close a channel
ch.close()

Select Coming soon

Wait on multiple channels simultaneously. The select expression is parsed but its full runtime is not yet complete — use individual channel send/recv patterns for now:

select {
    msg from inbox => handleMessage(msg)
    req from requests => handleRequest(req)
    after 5s => {
        println("timeout, no activity")
    }
}

Mutexes

Protect shared state:

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

  • spawn.detach — fire-and-forget background tasks
  • Directional channelschan.Send[T] and chan.Recv[T]
  • Cancellation tokens — cooperative task cancellation
  • RWMutex, Atomic, WaitGroup, Once, Barrier

Next Steps