Skip to content

Commit

Permalink
remove async NIOAsyncChannel API
Browse files Browse the repository at this point in the history
and other review comments
  • Loading branch information
rnro committed Aug 23, 2023
1 parent 00e829a commit e9d703b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 37 deletions.
22 changes: 0 additions & 22 deletions Sources/NIOHTTP2/HTTP2ChannelHandler+InlineStreamMultiplexer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -242,27 +242,5 @@ extension NIOHTTP2Handler {
public func createStreamChannel<OutboundStreamOutput>(_ initializer: @escaping NIOChannelInitializerWithOutput<OutboundStreamOutput>) async throws -> OutboundStreamOutput {
return try await self.inlineStreamMultiplexer.createStreamChannel(initializer).get()
}

/// Create a stream channel initialized with the provided closure and return it wrapped within a `NIOAsyncChannel`.
///
/// - Parameters:
/// - configuration: Configuration for the ``NIOAsyncChannel`` wrapping the HTTP/2 stream channel.
/// - initializer: A callback that will be invoked to allow you to configure the
/// `ChannelPipeline` for the newly created channel.
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
@_spi(AsyncChannel)
public func createStreamChannel<Inbound, Outbound>(
asyncChannelConfiguration: NIOAsyncChannel<Inbound, Outbound>.Configuration = .init(),
initializer: @escaping NIOChannelInitializer
) async throws -> NIOAsyncChannel<Inbound, Outbound> {
return try await self.createStreamChannel { channel in
initializer(channel).flatMapThrowing { _ in
return try NIOAsyncChannel(
synchronouslyWrapping: channel,
configuration: asyncChannelConfiguration
)
}
}
}
}
}
9 changes: 1 addition & 8 deletions Sources/NIOHTTP2/MultiplexerAbstractChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,7 @@ extension MultiplexerAbstractChannel {
case .includesStreamID(let initializer):
self.baseChannel.configure(initializer: initializer, userPromise: nil)
case .excludesStreamID(let initializer):
let channelPromise: EventLoopPromise<Channel>?
if let promise = promise {
channelPromise = self.baseChannel.eventLoop.makePromise(of: Channel.self)
channelPromise!.completeWith(promise.futureResult.map { value in value as! Channel })
} else {
channelPromise = nil
}
self.baseChannel.configure(initializer: initializer, userPromise: channelPromise)
self.baseChannel.configure(initializer: initializer, userPromise: nil)
case .returnsAny(let initializer):
self.baseChannel.configure(initializer: initializer, userPromise: promise)
}
Expand Down
17 changes: 10 additions & 7 deletions Tests/NIOHTTP2Tests/ConfiguringPipelineAsyncMultiplexerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,16 @@ final class ConfiguringPipelineAsyncMultiplexerTests: XCTestCase {

// client
for _ in 0 ..< requestCount {
let streamChannel = try await clientMultiplexer.createStreamChannel(
asyncChannelConfiguration: .init(
inboundType: HTTP2Frame.FramePayload.self,
outboundType: HTTP2Frame.FramePayload.self
)
) { channel -> EventLoopFuture<Void> in
channel.eventLoop.makeSucceededVoidFuture()
let streamChannel = try await clientMultiplexer.createStreamChannel() { channel in
channel.eventLoop.makeCompletedFuture {
try NIOAsyncChannel(
synchronouslyWrapping: channel,
configuration: .init(
inboundType: HTTP2Frame.FramePayload.self,
outboundType: HTTP2Frame.FramePayload.self
)
)
}
}
// Let's try sending some requests
try await streamChannel.outboundWriter.write(ConfiguringPipelineAsyncMultiplexerTests.requestFramePayload)
Expand Down

0 comments on commit e9d703b

Please sign in to comment.