<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/TaskGroup/cancelAll()",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:ScG9cancelAllyyF"
  },
  "title" : "cancelAll()"
}
-->

# cancelAll()

Cancel all of the remaining tasks in the group.

```
func cancelAll()
```

## 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.

> SeeAlso: `Task.isCancelled`

> SeeAlso: `TaskGroup.isCancelled`

---

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)