Demonstrates parallel I/O without threads or async/await. parallel and race are built-in step kinds that require no effect imports.
| File | Description |
|---|---|
structured-concurrency.cov |
Parallel fetches, race patterns, and timeout handling |
Execute branches concurrently and wait for all to complete:
step id="s1" kind="parallel"
branch id="b1"
step id="b1.1" kind="call"
fn="http.get"
arg name="url" lit="https://api.example.com/users"
as="users"
end
end
branch id="b2"
step id="b2.1" kind="call"
fn="http.get"
arg name="url" lit="https://api.example.com/products"
as="products"
end
end
as="results"
end
Execute branches and return the first to complete:
step id="s1" kind="race"
branch id="b1"
step id="b1.1" kind="call"
fn="redis.get"
arg name="key" from="key"
as="cached"
end
end
branch id="b2"
step id="b2.1" kind="call"
fn="postgres.query"
arg name="sql" lit="SELECT * FROM entries WHERE key = $1"
arg name="params" from="key"
as="db_result"
end
end
as="first_result"
end
on_error="fail_fast"(default) — Cancel other branches on first erroron_error="collect_all"— Wait for all branches, collect successes and failureson_error="ignore_errors"— Continue with successful results only
step id="s1" kind="parallel"
timeout=5s
on_timeout="cancel" // or "return_partial"
branch id="b1"
// ...
end
as="results"
end
- No threads — Concurrency without thread management
- No async/await — No function coloring
- Scoped — Always wait for results before proceeding
- Deterministic — Results collected in declaration order
- Isolated — Branches share no mutable state
- Built-in — No effect import required for
parallelorrace