Skip to content

std/concurrent

Import with import std/concurrent.

Types

type Task<'T>

In-flight or completed asynchronous computation. Task<'T> carries one type parameter — the body’s return type. Errors-as-values via Result<'T, 'E> are the universal Nomi idiom, so try Task.await(task) composes the same way try fetch_user(42) does.

Task<'T> values are scoped to the enclosing concurrent { } block: they cannot escape the block (the analyzer rejects return t, Channel.send(ch, t), etc.) and they must be consumed by Task.await (or explicitly discarded via _ = Task.await(t)). The analyzer enforces all of this: Task.async outside concurrent, un-awaited Task<'T> values, and Task<'T> escapes are rejected.

fn async<'T>(body: () -> 'T): Task<'T>

type function on Task

Spawn body as a parallel task in the enclosing concurrent { } block. Legal only inside the dynamic extent of concurrent { }; the analyzer rejects Task.async calls reachable from a function body without a concurrent ancestor.

Interactive Tests

value = concurrent {
  task = Task.async(|| 42)
  Task.await(task)
}
assert value == 42
fn await<'T>(task: Task<'T>): 'T

type function on Task

Block until task completes and return its value. Result-typed task bodies bubble errors through try Task.await(t) like any other Result-returning call.

Interactive Tests

value = concurrent {
  task = Task.async(|| "done")
  Task.await(task)
}
assert value == "done"

impl Debug

fn inspect<'T>(value: Task<'T>): String where 'T: Debug

impl Debug.inspect