Concurrency with a shape
In unstructured concurrency you can launch a background task and forget about it. It may outlive its caller, leak, or fail silently. Structured concurrency fixes this by binding tasks to a lexical scope. The scope does not finish until every child task it started has finished.
The scope contract
A structured scope enforces strong guarantees.
- No leaks because the scope waits for all children before returning.
- Error propagation because a child failure surfaces to the parent rather than vanishing.
- Cancellation because if the scope is cancelled, all children are cancelled too.
This mirrors how a function call returns only after its body completes, extending that discipline to concurrent children.
Why it tames complexity
Because tasks cannot escape their scope, you can reason locally. When a block returns, you know nothing it spawned is still running. Errors cannot be dropped, since an unhandled child error fails the whole scope. The result is concurrency that nests cleanly, just like ordinary control flow.
Key idea
Structured concurrency binds task lifetimes to a scope that waits for every child, so tasks never leak, errors propagate to the parent, and cancellation cascades, making concurrency nest like normal control flow.