Reference

std/task

Concurrent work: Task, a computation that finishes later, and Channel, a queue between two tasks.

Asynchrony lives in the type: a function that returns Task<Value> may call await(), and its body produces the Value - the same way a function that returns Result may use ?. Task and Channel are the two shared types that connect concurrent work; everything else is copied when it crosses into one.

Every task is cancellable (Task.cancel), and a cancellation is passed on rather than answered: await() answers the Value, and a task that awaits a task that ended cancelled is cancelled itself, right there - its scopes end and whoever awaits it is cancelled in turn. So an IO line is file.addLine(text).await()?, one ? for the failure of the work and nothing for a cancellation. Task.result is the one way to observe a cancellation as a value (Cancelled), for a supervisor or for code that cancelled a task and wants to confirm it.

Modules

Everything