<!--
{
  "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/ThrowingTaskGroup/waitForAll()",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:Scg10waitForAllyyYaKF"
  },
  "title" : "waitForAll()"
}
-->

# waitForAll()

Wait for all of the group’s remaining tasks to complete.

```
nonisolated(nonsending) mutating func waitForAll() async throws
```

## Discussion

If any of the tasks throw, the *first* error thrown is captured
and re-thrown by this method although the task group is *not* canceled
when this happens.

### Cancelling the task group on first error

If you want to cancel the task group, and all “sibling” tasks,
whenever any of child tasks throws an error, use the following pattern instead:

```
while !group.isEmpty {
    do {
        try await group.next()
    } catch is CancellationError {
        // we decide that cancellation errors thrown by children,
        // should not cause cancellation of the entire group.
        continue;
    } catch {
        // other errors though we print and cancel the group,
        // and all of the remaining child tasks within it.
        print("Error: \(error)")
        group.cancelAll()
    }
}
assert(group.isEmpty())
```

> Throws: The *first* error that was thrown by a child task during draining all the tasks.
> This first error is stored until all other tasks have completed, and is re-thrown afterwards.

---

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)