Module language::concurrency

Structured concurrency

Ordinary calls wait. fork creates a Task<T> and await task yields T. Awaiting a Vec<Task<T>> consumes it and yields Vec<T> in vector order. If T is a Result, each application error remains a value to handle.

A scope owns its child tasks and produces a value after their cleanup. A plain call in a scope is still a call; it does not implicitly start a task.

fn left() -> i64 { 20 }
fn right() -> i64 { 22 }
fn main() {
    let total = scope {
        let a = fork left();
        let b = fork right();
        (await a) + (await b)
    };
    println(total);
}

await fork [left(), right()] collects a vector; the parenthesized batch form collects a tuple. Each batch expression first creates a task.

scope within duration { ... } handle failure { ... } bounds structured work. A fault or cancellation settles children and cleanup before recovery; an ordinary Err does not trigger it. Parent cancellation continues outward. Cancellation is cooperative and cannot skip resource cleanup.

race chooses the first completion, including an ordinary Err, and cleans up losers. select uses value from source => ... and after duration => .... Task, timer and channel-receive selection are on the native path. Actor-call registration and stream selection remain pending at this checkpoint. Actor streams use ordinary for, without await.