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

# AsyncThrowingStream.Continuation

A mechanism to interface between synchronous code and an asynchronous
stream.

```
struct Continuation
```

## Overview

The closure you provide to the `AsyncThrowingStream` in
`init(_:bufferingPolicy:_:)` receives an instance of this type when
invoked. Use this continuation to provide elements to the stream by
calling one of the `yield` methods, then terminate the stream normally by
calling the `finish()` method. You can also use the continuation’s
`finish(throwing:)` method to terminate the stream by throwing an error.

> Note: Unlike other continuations in Swift,
> `AsyncThrowingStream.Continuation` supports escaping.

## Topics

### Producing Elements

[`func yield(sending Element) -> AsyncThrowingStream<Element, Failure>.Continuation.YieldResult`](/documentation/Swift/AsyncThrowingStream/Continuation/yield(_:))

Resume the task awaiting the next iteration point by having it return
normally from its suspension point with a given element.

[`func yield(with: sending Result<Element, Failure>) -> AsyncThrowingStream<Element, Failure>.Continuation.YieldResult`](/documentation/Swift/AsyncThrowingStream/Continuation/yield(with:))

Resume the task awaiting the next iteration point by having it return
normally or throw, based on a given result.

[`func yield() -> AsyncThrowingStream<Element, Failure>.Continuation.YieldResult`](/documentation/Swift/AsyncThrowingStream/Continuation/yield())

Resume the task awaiting the next iteration point by having it return
normally from its suspension point.

[`enum YieldResult`](/documentation/Swift/AsyncThrowingStream/Continuation/YieldResult)

A type that indicates the result of yielding a value to a client, by
way of the continuation.

### Finishing the Stream

[`func finish(throwing: Failure?)`](/documentation/Swift/AsyncThrowingStream/Continuation/finish(throwing:))

Resume the task awaiting the next iteration point by having it return
nil, which signifies the end of the iteration.

### Handling Termination

[`var onTermination: ((AsyncThrowingStream<Element, Failure>.Continuation.Termination) -> Void)?`](/documentation/Swift/AsyncThrowingStream/Continuation/onTermination)

A callback to invoke when canceling iteration of an asynchronous
stream.

[`enum Termination`](/documentation/Swift/AsyncThrowingStream/Continuation/Termination)

A type that indicates how the stream terminated.

### Enumerations

[`enum BufferingPolicy`](/documentation/Swift/AsyncThrowingStream/Continuation/BufferingPolicy)

A strategy that handles exhaustion of a buffer’s capacity.

### Default Implementations

[Equatable Implementations](/documentation/Swift/AsyncThrowingStream/Continuation/Equatable-Implementations)

[Hashable Implementations](/documentation/Swift/AsyncThrowingStream/Continuation/Hashable-Implementations)

## Relationships

### Conforms To

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

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

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

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

---

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)