---
title: "addTaskUnlessCancelled(executorPreference:priority:operation:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/throwingdiscardingtaskgroup/addtaskunlesscancelled(executorpreference:priority:operation:)"
---

# addTaskUnlessCancelled(executorPreference:priority:operation:)

Adds a child task to the group, unless the group has been canceled. Returns a boolean value indicating if the task was successfully added to the group or not.

## Declaration

```swift
mutating func addTaskUnlessCancelled(executorPreference taskExecutor: (any TaskExecutor)? = nil, priority: TaskPriority? = nil, operation: sending @escaping @isolated(any) () async throws -> Void) -> Bool
```

## Parameters

- `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 addTaskUnlessCancelled method without a preference, and effectively means to inherit the outer context’s executor preference. You can also pass the doc://com.apple.Swift/documentation/Swift/globalConcurrentExecutor global executor explicitly.
- `priority`: The priority of the operation task. Omit this parameter or pass nil to inherit the task group’s base priority.
- `operation`: The operation to execute as part of the task group.

## Return Value

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

## Discussion

Discussion This method doesn’t throw an error, even if the child task does. Instead, the corresponding call to ThrowingTaskGroup.next() rethrows that error.
