Mojo struct
TaskGroup
struct TaskGroup
A group of tasks that can be executed concurrently.
TaskGroup manages a collection of coroutines that can be executed in parallel. It provides mechanisms to create, track, and wait for the completion of tasks.
Fields
- counter (
Atomic[index]
): Atomic counter tracking the number of active tasks in the group. - chain (
_Chain
): Chain used for asynchronous completion notification. - tasks (
List[_TaskGroupBox]
): Collection of tasks managed by this TaskGroup.
Implemented traits
AnyType
,
UnknownDestructibility
Methods
__init__
__init__(out self)
Initialize a new TaskGroup with an empty task list and initialized chain.
__del__
__del__(owned self)
Clean up resources associated with the TaskGroup.
__await__
__await__(mut self)
Make TaskGroup awaitable in async contexts.
This allows using 'await task_group' syntax in async functions.
create_task
create_task(mut self, owned task: Coroutine[None, origins])
Add a new task to the TaskGroup for execution.
Args:
- task (
Coroutine[None, origins]
): The coroutine to be executed as a task.
await_body_impl
static await_body_impl(hdl: !co.routine, mut task_group: Self)
Implementation of the await functionality for TaskGroup.
Args:
- hdl (
!co.routine
): The coroutine handle to be awaited. - task_group (
Self
): The TaskGroup to be awaited.
wait
wait[origins: origin.set = {}](mut self)
Wait for all tasks in the TaskGroup
to complete.
This is a blocking call that returns only when all tasks have finished.
Parameters:
- origins (
origin.set
): The origin set for the wait operation.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!