# SE-0314: AsyncStream and AsyncThrowingStream

**URL:** <https://forums.swift.org/t/se-0314-asyncstream-and-asyncthrowingstream/48198>\
**Category:** Proposal Reviews\
**Created:** [May 11, 2021, 7:50pm UTC](https://forums.swift.org/t/se-0314-asyncstream-and-asyncthrowingstream/48198 "2021-05-11T19:50:32Z")\
**Posts on this page:** 1\
**Showing post:** 20

<div class="post-metadata">

**Author:** ![Philippe\_Hausler](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/philippe_hausler/32/22569_2.png) [@Philippe\_Hausler](https://forums.swift.org/u/Philippe_Hausler)\
**Post date:** [June 14, 2021, 7:46pm UTC](https://forums.swift.org/t/se-0314-asyncstream-and-asyncthrowingstream/48198/20 "2021-06-14T19:46:40Z")

</div>

> [@anandabits](#):
>
> this should probably have a typed error.

After talking with @Douglas_Gregor a bit more I think we are in agreement this is a sensible approach here. I will have this updated on the proposal to reflect the following:

```swift
public struct AsyncThrowingStream<Element, Failure: Error> {
  public struct Continuation: Sendable {
    public enum Termination {
      case finished(Failure?)
      case cancelled
    }
    
    /// * See AsyncStream.Continuation.yield(_:) *
    public func yield(_ value: Element)

    /// Resume the task awaiting the next iteration point with a terminal state.
    /// If error is nil, this is a completion with out error. If error is not 
    /// nil, then the error is thrown. Both of these states indicate the 
    /// end of iteration.
    ///
    /// - Parameter error: The error to throw or nil to signify termination.
    ///
    /// Calling this function more than once is idempotent. All values received
    /// from the iterator after it is finished and after the buffer is exhausted 
    /// are nil.
    public func finish(throwing error: Failure? = nil)

    /// * See AsyncStream.Continuation.onTermination *
    public var onTermination: (@Sendable (Termination) -> Void)? { get nonmutating set }
  }

  /// * See AsyncStream.init *
  public init(
    _ elementType: Element.Type,
    maxBufferedElements limit: Int = .max,
    _ build: (Continuation) -> Void
  ) where Failure == Error
}

```

---

_[View the full topic](https://forums.swift.org/t/se-0314-asyncstream-and-asyncthrowingstream/48198)._
