35
35
@available ( macOS 10 . 15 , iOS 13 , tvOS 13 , watchOS 6 , * )
36
36
@_spi ( AsyncChannel)
37
37
public final class NIOAsyncChannel < Inbound: Sendable , Outbound: Sendable > : Sendable {
38
+ @_spi ( AsyncChannel)
39
+ public struct Configuration {
40
+ /// The backpressure strategy of the ``NIOAsyncChannel/inboundStream``.
41
+ public var backpressureStrategy : NIOAsyncSequenceProducerBackPressureStrategies . HighLowWatermark
42
+
43
+ /// If outbound half closure should be enabled. Outbound half closure is triggered once
44
+ /// the ``NIOAsyncChannelWriter`` is either finished or deinitialized.
45
+ public var isOutboundHalfClosureEnabled : Bool
46
+
47
+ /// The ``NIOAsyncChannel/inboundStream`` message's type.
48
+ public var inboundType : Inbound . Type
49
+
50
+ /// The ``NIOAsyncChannel/outboundWriter`` message's type.
51
+ public var outboundType : Outbound . Type
52
+
53
+ /// Initializes a new ``NIOAsyncChannel/Configuration``.
54
+ ///
55
+ /// - Parameters:
56
+ /// - backpressureStrategy: The backpressure strategy of the ``NIOAsyncChannel/inboundStream``. Defaults
57
+ /// to a watermarked strategy (lowWatermark: 2, highWatermark: 10).
58
+ /// - isOutboundHalfClosureEnabled: If outbound half closure should be enabled. Outbound half closure is triggered once
59
+ /// the ``NIOAsyncChannelWriter`` is either finished or deinitialized. Defaults to `false`.
60
+ /// - inboundType: The ``NIOAsyncChannel/inboundStream`` message's type.
61
+ /// - outboundType: The ``NIOAsyncChannel/outboundWriter`` message's type.
62
+ public init (
63
+ backpressureStrategy: NIOAsyncSequenceProducerBackPressureStrategies . HighLowWatermark = . init( lowWatermark: 2 , highWatermark: 10 ) ,
64
+ isOutboundHalfClosureEnabled: Bool = false ,
65
+ inboundType: Inbound . Type = Inbound . self,
66
+ outboundType: Outbound . Type = Outbound . self
67
+ ) {
68
+ self . backpressureStrategy = backpressureStrategy
69
+ self . isOutboundHalfClosureEnabled = isOutboundHalfClosureEnabled
70
+ self . inboundType = inboundType
71
+ self . outboundType = outboundType
72
+ }
73
+ }
74
+
38
75
/// The underlying channel being wrapped by this ``NIOAsyncChannel``.
39
76
@_spi ( AsyncChannel)
40
77
public let channel : Channel
@@ -52,25 +89,18 @@ public final class NIOAsyncChannel<Inbound: Sendable, Outbound: Sendable>: Senda
52
89
///
53
90
/// - Parameters:
54
91
/// - channel: The ``Channel`` to wrap.
55
- /// - backpressureStrategy: The backpressure strategy of the ``NIOAsyncChannel/inboundStream``.
56
- /// - isOutboundHalfClosureEnabled: If outbound half closure should be enabled. Outbound half closure is triggered once
57
- /// the ``NIOAsyncChannelWriter`` is either finished or deinitialized.
58
- /// - inboundType: The ``NIOAsyncChannel/inboundStream`` message's type.
59
- /// - outboundType: The ``NIOAsyncChannel/outboundWriter`` message's type.
92
+ /// - configuration: The ``NIOAsyncChannel``s configuration.
60
93
@inlinable
61
94
@_spi ( AsyncChannel)
62
95
public init (
63
96
synchronouslyWrapping channel: Channel ,
64
- backpressureStrategy: NIOAsyncSequenceProducerBackPressureStrategies . HighLowWatermark ? = nil ,
65
- isOutboundHalfClosureEnabled: Bool = false ,
66
- inboundType: Inbound . Type = Inbound . self,
67
- outboundType: Outbound . Type = Outbound . self
97
+ configuration: Configuration = . init( )
68
98
) throws {
69
99
channel. eventLoop. preconditionInEventLoop ( )
70
100
self . channel = channel
71
101
( self . inboundStream, self . outboundWriter) = try channel. _syncAddAsyncHandlers (
72
- backpressureStrategy: backpressureStrategy,
73
- isOutboundHalfClosureEnabled: isOutboundHalfClosureEnabled
102
+ backpressureStrategy: configuration . backpressureStrategy,
103
+ isOutboundHalfClosureEnabled: configuration . isOutboundHalfClosureEnabled
74
104
)
75
105
}
76
106
@@ -83,23 +113,18 @@ public final class NIOAsyncChannel<Inbound: Sendable, Outbound: Sendable>: Senda
83
113
///
84
114
/// - Parameters:
85
115
/// - channel: The ``Channel`` to wrap.
86
- /// - backpressureStrategy: The backpressure strategy of the ``NIOAsyncChannel/inboundStream``.
87
- /// - isOutboundHalfClosureEnabled: If outbound half closure should be enabled. Outbound half closure is triggered once
88
- /// the ``NIOAsyncChannelWriter`` is either finished or deinitialized.
89
- /// - inboundType: The ``NIOAsyncChannel/inboundStream`` message's type.
116
+ /// - configuration: The ``NIOAsyncChannel``s configuration.
90
117
@inlinable
91
118
@_spi ( AsyncChannel)
92
119
public init (
93
120
synchronouslyWrapping channel: Channel ,
94
- backpressureStrategy: NIOAsyncSequenceProducerBackPressureStrategies . HighLowWatermark ? = nil ,
95
- isOutboundHalfClosureEnabled: Bool = false ,
96
- inboundType: Inbound . Type = Inbound . self
121
+ configuration: Configuration
97
122
) throws where Outbound == Never {
98
123
channel. eventLoop. preconditionInEventLoop ( )
99
124
self . channel = channel
100
125
( self . inboundStream, self . outboundWriter) = try channel. _syncAddAsyncHandlers (
101
- backpressureStrategy: backpressureStrategy,
102
- isOutboundHalfClosureEnabled: isOutboundHalfClosureEnabled
126
+ backpressureStrategy: configuration . backpressureStrategy,
127
+ isOutboundHalfClosureEnabled: configuration . isOutboundHalfClosureEnabled
103
128
)
104
129
105
130
self . outboundWriter. finish ( )
@@ -125,7 +150,7 @@ public final class NIOAsyncChannel<Inbound: Sendable, Outbound: Sendable>: Senda
125
150
backpressureStrategy: NIOAsyncSequenceProducerBackPressureStrategies . HighLowWatermark ? = nil ,
126
151
isOutboundHalfClosureEnabled: Bool = false ,
127
152
channelReadTransformation: @Sendable @escaping ( Channel ) -> EventLoopFuture < ChannelReadResult > ,
128
- postFireChannelReadTransformation: @Sendable @escaping ( ChannelReadResult ) -> EventLoopFuture < Inbound >
153
+ postFireChannelReadTransformation: @Sendable @escaping ( ChannelReadResult ) -> EventLoopFuture < Inbound >
129
154
) throws -> NIOAsyncChannel < Inbound , Outbound > where Outbound == Never {
130
155
channel. eventLoop. preconditionInEventLoop ( )
131
156
let ( inboundStream, outboundWriter) : ( NIOAsyncChannelInboundStream < Inbound > , NIOAsyncChannelOutboundWriter < Outbound > ) = try channel. _syncAddAsyncHandlersWithTransformations (
0 commit comments