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

# nextResult()

Wait for the next child task to complete,
and return a result containing either
the value that the child task returned or the error that it threw.

```
nonisolated(nonsending) mutating func nextResult() async -> Result<ChildTaskResult, Failure>?
```

## Return Value

A `Result.success` value
containing the value that the child task returned,
or a `Result.failure` value
containing the error that the child task threw.

## Discussion

The values returned by successive calls to this method
appear in the order that the tasks *completed*,
not in the order that those tasks were added to the task group.
For example:

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

guard let result = await group.nextResult() else {
    return  // No task to wait on, which won't happen in this example.
}

switch result {
case .success(let value): print(value)
case .failure(let error): print("Failure: \(error)")
}
// Prints either "2" or "1".
```

If the next child task throws an error
and you propagate that error from this method
out of the body of a call to the
`ThrowingTaskGroup.withThrowingTaskGroup(of:returning:body:)` method,
then all remaining child tasks in that group are implicitly canceled.

> SeeAlso: `next()`

---

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)