---
title: cancelAll()
framework: swift
role: symbol
role_heading: Instance Method
path: swift/throwingdiscardingtaskgroup/cancelall()
---

# cancelAll()

Cancel all of the remaining tasks in the group.

## Declaration

```swift
func cancelAll()
```

## Discussion

Discussion If you add a task to a group after canceling the group, that task is canceled immediately after being added to the group. Immediately canceled child tasks should therefore cooperatively check for and react  to cancellation, e.g. by throwing an CancellationError at their earliest convenience, or otherwise handling the cancellation. There are no restrictions on where you can call this method. Code inside a child task or even another task can cancel a group, however one should be very careful to not keep a reference to the group longer than the with...TaskGroup(...) { ... } method body is executing. note: Task.isCancelled note: ThrowingDiscardingTaskGroup.isCancelled
