Concurrent work#
Ordinary calls run sequentially. Use a task group or scheduler when operations should run at the same time. Both accept ordinary functions; there is no separate async declaration.
Read these pages in order:
- Starting tasks : run operations together and collect typed results.
- Waiting for tasks : understand success, failure, and group shutdown.
- Cancellation and timeouts : request a stop and set time budgets.
- Scheduling work : run delayed or repeating work under a service lifetime.
- Sharing data : distinguish shared references from safe concurrent access.
- Synchronizing updates : protect a complete read-and-write operation with a lock.
- Queues : store pending values locally or protect a shared queue.
Fixed lifetimes#
A task group belongs to the execution that constructs it. Its tasks finish and run cleanup before the group closes. A scheduler likewise keeps its construction lifetime; submitting from another request does not change that relationship.
References to a task, scheduler, or resource do not prolong its lifetime. Keep dependencies open until their work finishes, and acquire per-operation resources inside the operation’s own with block. See managing resources
.
Compiler contributors can read the runtime contracts for transition and acquisition details.