@@ -24,10 +24,10 @@ public struct NIOAsyncChannelInboundStream<Inbound: Sendable>: Sendable {
24
24
/// A source used for driving a ``NIOAsyncChannelInboundStream`` during tests.
25
25
public struct TestSource {
26
26
@usableFromInline
27
- internal let continuation : AsyncStream < Inbound > . Continuation
27
+ internal let continuation : AsyncThrowingStream < Inbound , Error > . Continuation
28
28
29
29
@inlinable
30
- init ( continuation: AsyncStream < Inbound > . Continuation ) {
30
+ init ( continuation: AsyncThrowingStream < Inbound , Error > . Continuation ) {
31
31
self . continuation = continuation
32
32
}
33
33
@@ -40,23 +40,25 @@ public struct NIOAsyncChannelInboundStream<Inbound: Sendable>: Sendable {
40
40
}
41
41
42
42
/// Finished the inbound stream.
43
+ ///
44
+ /// - Parameter error: The error to throw, or nil, to finish normally.
43
45
@inlinable
44
- public func finish( ) {
45
- self . continuation. finish ( )
46
+ public func finish( throwing error : Error ? = nil ) {
47
+ self . continuation. finish ( throwing : error )
46
48
}
47
49
}
48
50
49
51
#if swift(>=5.7)
50
52
@usableFromInline
51
53
enum _Backing : Sendable {
52
- case asyncStream( AsyncStream < Inbound > )
54
+ case asyncStream( AsyncThrowingStream < Inbound , Error > )
53
55
case producer( Producer )
54
56
}
55
57
#else
56
58
// AsyncStream wasn't marked as `Sendable` in 5.6
57
59
@usableFromInline
58
60
enum _Backing : @unchecked Sendable {
59
- case asyncStream( AsyncStream < Inbound > )
61
+ case asyncStream( AsyncThrowingStream < Inbound , Error > )
60
62
case producer( Producer )
61
63
}
62
64
#endif
@@ -72,15 +74,15 @@ public struct NIOAsyncChannelInboundStream<Inbound: Sendable>: Sendable {
72
74
/// - Returns: A tuple containing the input stream and a test source to drive it.
73
75
@inlinable
74
76
public static func makeTestingStream( ) -> ( Self , TestSource ) {
75
- var continuation : AsyncStream < Inbound > . Continuation !
76
- let stream = AsyncStream < Inbound> { continuation = $0 }
77
+ var continuation : AsyncThrowingStream < Inbound , Error > . Continuation !
78
+ let stream = AsyncThrowingStream < Inbound , Error > { continuation = $0 }
77
79
let source = TestSource ( continuation: continuation)
78
80
let inputStream = Self ( stream: stream)
79
81
return ( inputStream, source)
80
82
}
81
83
82
84
@inlinable
83
- init ( stream: AsyncStream < Inbound > ) {
85
+ init ( stream: AsyncThrowingStream < Inbound , Error > ) {
84
86
self . _backing = . asyncStream( stream)
85
87
}
86
88
@@ -163,7 +165,7 @@ extension NIOAsyncChannelInboundStream: AsyncSequence {
163
165
public struct AsyncIterator : AsyncIteratorProtocol {
164
166
@usableFromInline
165
167
enum _Backing {
166
- case asyncStream( AsyncStream < Inbound > . Iterator )
168
+ case asyncStream( AsyncThrowingStream < Inbound , Error > . Iterator )
167
169
case producer( Producer . AsyncIterator )
168
170
}
169
171
@@ -183,8 +185,10 @@ extension NIOAsyncChannelInboundStream: AsyncSequence {
183
185
public mutating func next( ) async throws -> Element ? {
184
186
switch self . _backing {
185
187
case . asyncStream( var iterator) :
186
- let value = await iterator. next ( )
187
- self . _backing = . asyncStream( iterator)
188
+ defer {
189
+ self . _backing = . asyncStream( iterator)
190
+ }
191
+ let value = try await iterator. next ( )
188
192
return value
189
193
190
194
case . producer( let iterator) :
0 commit comments