Docs
Tasks
Spawn work, capture values, and join task handles.
Spawn and join
$ inc = (x) {
^ x + 1
}
+ job = inc(41)
- answer = job+ schedules a free-function call or task body. Binding the spawn result stores a task handle. - handle waits and discards the result; - name = handle waits and binds it.
Task bodies and captures
$ base = 40
+ job = () [base] {
^ base + 2
}
- answer = jobA task body is closed to outer locals unless they are named in its optional capture list. Captures must already be bound and are passed by reference. Reference values share their object; value kinds carry the same value. A spawn call or capture list accepts up to eight values.
Immediate block
- { body } schedules and joins a body in one statement. Use - name = { body } to keep its return value. Result- and option-shaped task returns are handled with the same match forms as ordinary function calls.
- result = {
^ 42
}Lifecycle rule
Every spawned task must be joined before process exit. Leaving a task handle unjoined makes the program exit unsuccessfully. Task scheduling is a language feature; userland does not import a task module.