<!--
{
  "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/Iterator",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:Scg8IteratorV"
  },
  "title" : "ThrowingTaskGroup.Iterator"
}
-->

# ThrowingTaskGroup.Iterator

A type that provides an iteration interface
over the results of tasks added to the group.

```
struct Iterator
```

## Overview

The elements returned by this iterator
appear in the order that the tasks *completed*,
not in the order that those tasks were added to the task group.

This iterator terminates after all tasks have completed successfully,
or after any task completes by throwing an error.
If a task completes by throwing an error,
it doesn’t return any further task results.
After iterating over the results of each task,
it’s valid to make a new iterator for the task group,
which you can use to iterate over the results of new tasks you add to the group.
You can also make a new iterator to resume iteration
after a child task throws an error.
For example:

```
group.addTask { 1 }
group.addTask { throw SomeError }
group.addTask { 2 }

do {
    // Assuming the child tasks complete in order, this prints "1"
    // and then throws an error.
    for try await r in group { print(r) }
} catch {
    // Resolve the error.
}

// Assuming the child tasks complete in order, this prints "2".
for try await r in group { print(r) }
```

> SeeAlso: `ThrowingTaskGroup.next()`

## Topics

### Instance Methods

[`func cancel()`](/documentation/Swift/ThrowingTaskGroup/Iterator/cancel())

[`func next() async throws -> ThrowingTaskGroup<ChildTaskResult, Failure>.Iterator.Element?`](/documentation/Swift/ThrowingTaskGroup/Iterator/next())

Advances to and returns the result of the next child task.

[`func next(isolation: isolated (any Actor)?) async throws(Failure) -> ThrowingTaskGroup<ChildTaskResult, Failure>.Iterator.Element?`](/documentation/Swift/ThrowingTaskGroup/Iterator/next(isolation:))

Advances to and returns the result of the next child task.

### Type Aliases

[`typealias Element`](/documentation/Swift/ThrowingTaskGroup/Iterator/Element)

### Default Implementations

[AsyncIteratorProtocol Implementations](/documentation/Swift/ThrowingTaskGroup/Iterator/AsyncIteratorProtocol-Implementations)

## Relationships

### Conforms To

[`AsyncIteratorProtocol`](/documentation/Swift/AsyncIteratorProtocol)

---

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)