addImmediateTask(name:priority:executorPreference:operation:)
Add a child task to the group and immediately start running it in the context of the calling thread/task.
Declaration
mutating func addImmediateTask(name: String? = nil, priority: TaskPriority? = nil, executorPreference taskExecutor: consuming (any TaskExecutor)? = nil, operation: sending @escaping @isolated(any) () async -> ChildTaskResult)Parameters
- name:
Human readable name of this task.
- priority:
The priority of the operation task. Omit this parameter or pass
nilto inherit the task group’s base priority. - taskExecutor:
The task executor that the child task should be started on and keep using. Explicitly passing
nilas the executor preference is equivalent to calling theaddImmediateTaskmethod without a preference, and effectively means to inherit the outer context’s executor preference. You can also pass the Globalconcurrentexecutor global executor explicitly. - operation:
The operation to execute as part of the task group.
Discussion
This function starts the created task on the calling context. The task will continue executing on the caller’s context until it suspends, and after suspension will resume on the adequate executor. For a nonisolated operation this means running on the global concurrent pool, and on an isolated operation it means the appropriate executor of that isolation context.
As indicated by the lack of async on this method, this method does not suspend, and instead takes over the calling task’s (thread’s) execution in a synchronous manner.
Other than the execution semantics discussed above, the created task is semantically equivalent to its basic version which can be created using TaskGroup/addTask.
See Also
Adding Tasks to a Task Group
addTask(priority:operation:)addTask(name:priority:operation:)addTask(executorPreference:priority:operation:)addTask(name:executorPreference:priority:operation:)addTaskUnlessCancelled(name:executorPreference:priority:operation:)addTaskUnlessCancelled(executorPreference:priority:operation:)addTaskUnlessCancelled(name:priority:operation:)addTaskUnlessCancelled(priority:operation:)addImmediateTaskUnlessCancelled(name:priority:executorPreference:operation:)