Repository: apple/swift-nio
File: Sources/NIOCore/AsyncChannel/AsyncChannelInboundStream.swift (Swift)

Code before:
    @usableFromInline
    typealias Producer = NIOThrowingAsyncSequenceProducer<Inbound, Error, NIOAsyncSequenceProducerBackPressureStrategies.HighLowWatermark, NIOAsyncChannelInboundStreamChannelHandlerProducerDelegate>

    /// A source used for driving a ``NIOAsyncChannelInboundStream`` during tests.
    public struct TestSource {
        @usableFromInline
        internal let continuation: AsyncThrowingStream<Inbound, Error>.Continuation

        @inlinable
        init(continuation: AsyncThrowingStream<Inbound, Error>.Continuation) {
            self.continuation = continuation
        }

        /// Yields the element to the inbound stream.
        ///
        /// - Parameter element: The element to yield to the inbound stream.
        @inlinable
        public func yield(_ element: Inbound) {
            self.continuation.yield(element)
        }

        /// Finished the inbound stream.
        ///
        /// - Parameter error: The error to throw, or nil, to finish normally.
        @inlinable
        public func finish(throwing error: Error?) {
            self.continuation.finish(throwing: error)
        }
    }

    #if swift(>=5.7)
    @usableFromInline
    enum _Backing: Sendable {
        case asyncStream(AsyncThrowingStream<Inbound, Error>)
        case producer(Producer)
    }
    #else
    // AsyncStream wasn't marked as `Sendable` in 5.6
    @usableFromInline
    enum _Backing: @unchecked Sendable {
        case asyncStream(AsyncThrowingStream<Inbound, Error>)
        case producer(Producer)
    }
    #endif

    /// The underlying async sequence.
    @usableFromInline
    let _backing: _Backing

    /// Creates a new stream with a source for testing.
    ///

Review comment (suggestion):
I think we should default this to `nil`. Having to spell out `finish(throwing: nil)` for a 'happy-path' finish is a bit awkward IMO.

Code after:
    @usableFromInline
    typealias Producer = NIOThrowingAsyncSequenceProducer<Inbound, Error, NIOAsyncSequenceProducerBackPressureStrategies.HighLowWatermark, NIOAsyncChannelInboundStreamChannelHandlerProducerDelegate>

    /// A source used for driving a ``NIOAsyncChannelInboundStream`` during tests.
    public struct TestSource {
        @usableFromInline
        internal let continuation: AsyncThrowingStream<Inbound, Error>.Continuation

        @inlinable
        init(continuation: AsyncThrowingStream<Inbound, Error>.Continuation) {
            self.continuation = continuation
        }

        /// Yields the element to the inbound stream.
        ///
        /// - Parameter element: The element to yield to the inbound stream.
        @inlinable
        public func yield(_ element: Inbound) {
            self.continuation.yield(element)
        }

        /// Finished the inbound stream.
        ///
        /// - Parameter error: The error to throw, or nil, to finish normally.
        @inlinable
        public func finish(throwing error: Error? = nil) {
            self.continuation.finish(throwing: error)
        }
    }

    #if swift(>=5.7)
    @usableFromInline
    enum _Backing: Sendable {
        case asyncStream(AsyncThrowingStream<Inbound, Error>)
        case producer(Producer)
    }
    #else
    // AsyncStream wasn't marked as `Sendable` in 5.6
    @usableFromInline
    enum _Backing: @unchecked Sendable {
        case asyncStream(AsyncThrowingStream<Inbound, Error>)
        case producer(Producer)
    }
    #endif

    /// The underlying async sequence.
    @usableFromInline
    let _backing: _Backing

    /// Creates a new stream with a source for testing.
    ///