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

# AsyncStream.Continuation

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

```
struct Continuation
```

## Overview

The closure you provide to the `AsyncStream` 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.

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

## Topics

### Producing Elements

[`yield(_:)`](/documentation/Swift/AsyncStream/Continuation/yield(_:))

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

[`yield(with:)`](/documentation/Swift/AsyncStream/Continuation/yield(with:))

Resume the task awaiting the next iteration point by having it return
normally from its suspension point with a given result’s success value.

[`yield()`](/documentation/Swift/AsyncStream/Continuation/yield())

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

[`AsyncStream.Continuation.YieldResult`](/documentation/Swift/AsyncStream/Continuation/YieldResult)

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

### Finishing the Stream

[`finish()`](/documentation/Swift/AsyncStream/Continuation/finish())

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

### Handling Termination

[`onTermination`](/documentation/Swift/AsyncStream/Continuation/onTermination)

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

[`AsyncStream.Continuation.Termination`](/documentation/Swift/AsyncStream/Continuation/Termination)

A type that indicates how the stream terminated.



---

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)