diff --git a/Sources/NIOHTTP2/HTTP2StreamChannel.swift b/Sources/NIOHTTP2/HTTP2StreamChannel.swift index 165b87a..889fac0 100644 --- a/Sources/NIOHTTP2/HTTP2StreamChannel.swift +++ b/Sources/NIOHTTP2/HTTP2StreamChannel.swift @@ -100,8 +100,7 @@ final class HTTP2StreamChannel: Channel, ChannelCore { self._pipeline = ChannelPipeline(channel: self) } - @discardableResult - internal func configure(initializer: ((Channel, HTTP2StreamID) -> EventLoopFuture)?) -> EventLoopFuture { + internal func configure(initializer: ((Channel, HTTP2StreamID) -> EventLoopFuture)?, userPromise promise: EventLoopPromise?){ // We need to configure this channel. This involves doing four things: // 1. Setting our autoRead state from the parent // 2. Calling the initializer, if provided. @@ -116,6 +115,9 @@ final class HTTP2StreamChannel: Channel, ChannelCore { if self.parent!.isActive { self.performActivation() } + + // We aren't using cascade here to avoid the allocations it causes. + promise?.succeed(self) } f.whenFailure { (error: Error) in @@ -124,8 +126,9 @@ final class HTTP2StreamChannel: Channel, ChannelCore { } else { self.errorEncountered(error: error) } + + promise?.fail(error) } - return f } /// Activates this channel. diff --git a/Sources/NIOHTTP2/HTTP2StreamMultiplexer.swift b/Sources/NIOHTTP2/HTTP2StreamMultiplexer.swift index 331a4e7..a9d1a23 100644 --- a/Sources/NIOHTTP2/HTTP2StreamMultiplexer.swift +++ b/Sources/NIOHTTP2/HTTP2StreamMultiplexer.swift @@ -64,7 +64,7 @@ public final class HTTP2StreamMultiplexer: ChannelInboundHandler, ChannelOutboun targetWindowSize: 65535, initiatedRemotely: true) self.streams[streamID] = channel - channel.configure(initializer: self.inboundStreamStateInitializer) + channel.configure(initializer: self.inboundStreamStateInitializer, userPromise: nil) channel.closeFuture.whenComplete { _ in self.childChannelClosed(streamID: streamID) } @@ -184,14 +184,10 @@ extension HTTP2StreamMultiplexer { targetWindowSize: 65535, // TODO: make configurable initiatedRemotely: false) self.streams[streamID] = channel - let activationFuture = channel.configure(initializer: streamStateInitializer) + channel.configure(initializer: streamStateInitializer, userPromise: promise) channel.closeFuture.whenComplete { _ in self.childChannelClosed(streamID: streamID) } - - if let promise = promise { - activationFuture.map { channel }.cascade(to: promise) - } } } }