veko doc
Self-Contained API Reference • Gradual Types • Capabilities • Wasm Sandbox

conc/scope

lib/conc/scope.vk

lib/conc/scope.vk Structured task-group concurrency helpers over Veko's shared-nothing spawn and task/await. Ensures every spawned task in a Scope is awaited before scope completion so zero orphan tasks leak, propagating the first worker err (combine with /or).

Scope struct
signature
Scope = struct { tasks block }

Structured group of spawned task handles.

new fn
signature
new = fn [] Scope

Creates a new empty structured concurrency Scope.

Executable Example
veko
use [sc = conc/scope]
mut grp = sc/new
sc/add mut grp (spawn [ 10 + 11 ])
sc/add mut grp (spawn [ 20 + 1 ])
res = sc/await-all mut grp
if (len res) != 2 or res[0] != 21 or res[1] != 21 [ err 'scope await-all' ] else [ .ok ]
add fn
signature
add = fn [mut s Scope, task_handle any]

Registers a spawned task handle (spawn [ ... ]) with s.

signature
await-all = fn [mut s Scope] block

Awaits all tasks in s in registration order, draining every handle even if an earlier task errored, and returns the ordered block of results (or the first err encountered).

signature
await-settled = fn [mut s Scope] map

Awaits all tasks in s and returns { ok = block, errors = block } without short-circuiting.