<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: 26.0.0 -",
    "macOS: 26.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 26.0.0 -",
    "watchOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/ThrowingTaskGroup/addImmediateTaskUnlessCancelled(name:priority:executorPreference:operation:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:Scg31addImmediateTaskUnlessCancelled4name8priority18executorPreference9operationSbSSSg_ScPSgSch_pSgnxyYaKYAcntF"
  },
  "title" : "addImmediateTaskUnlessCancelled(name:priority:executorPreference:operation:)"
}
-->

# addImmediateTaskUnlessCancelled(name:priority:executorPreference:operation:)

Add a child task to the group and immediately start running it in the context of the calling thread/task.

```
mutating func addImmediateTaskUnlessCancelled(name: String? = nil, priority: TaskPriority? = nil, executorPreference taskExecutor: consuming (any TaskExecutor)? = nil, operation: sending @escaping @isolated(any) () async throws -> ChildTaskResult) -> Bool
```

## Parameters

`name`

Human readable name of this task.

`priority`

The priority of the operation task.
Omit this parameter or pass `nil` to inherit the task group’s base priority.

`taskExecutor`

The task executor that the child task should be started on and keep using.
Explicitly passing `nil` as the executor preference is equivalent to
calling the `addImmediateTaskUnlessCancelled` method without a preference, and effectively
means to inherit the outer context’s executor preference.
You can also pass the [`globalConcurrentExecutor`](/documentation/Swift/globalConcurrentExecutor) global executor explicitly.

`operation`

The operation to execute as part of the task group.

## Return Value

`true` if the child task was added to the group;
otherwise `false`.

## 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 [`addTask(priority:operation:)`](/documentation/Swift/ThrowingTaskGroup/addTask(priority:operation:)).

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)