Replace Future with a function call. (#116)

Motivation:

Sometimes when you have a hammer everything looks like a nail.
In this case, my hammer was Futures. But we don't need to use a
Future here: these two classes are tightly coupled, and so we can
safely just call from one to the other.

A side note: while this appears to create a reference cycle, the
act of calling the function in question will actually break that
cycle. So it's all good!

Modifications:

- Remove a future callback.
- Have the stream channel hold a reference to the multiplexer.

Result:

Fewer heap allocations.
This commit is contained in:
Cory Benfield authored and GitHub committed 2019-05-16 15:17:19 +01:00
1 parent 016bf0be4d
commit f1cc1f5069
2 files changed
+9 -8

No files matched your search

+6 -1
View File
@@ -76,7 +76,7 @@ private enum StreamChannelState {
final class HTTP2StreamChannel: Channel, ChannelCore {
internal init(allocator: ByteBufferAllocator, parent: Channel, streamID: HTTP2StreamID, targetWindowSize: Int32, initiatedRemotely: Bool) {
internal init(allocator: ByteBufferAllocator, parent: Channel, multiplexer: HTTP2StreamMultiplexer, streamID: HTTP2StreamID, targetWindowSize: Int32, initiatedRemotely: Bool) {
self.allocator = allocator
self.closePromise = parent.eventLoop.makePromise()
self.localAddress = parent.localAddress
@@ -84,6 +84,7 @@ final class HTTP2StreamChannel: Channel, ChannelCore {
self.parent = parent
self.eventLoop = parent.eventLoop
self.streamID = streamID
self.multiplexer = multiplexer
self.windowManager = InboundWindowManager(targetSize: Int32(targetWindowSize))
// FIXME: that's just wrong
self.isWritable = true
@@ -148,6 +149,8 @@ final class HTTP2StreamChannel: Channel, ChannelCore {
private let closePromise: EventLoopPromise<()>
private let multiplexer: HTTP2StreamMultiplexer
public var closeFuture: EventLoopFuture<Void> {
return self.closePromise.futureResult
}
@@ -373,6 +376,7 @@ final class HTTP2StreamChannel: Channel, ChannelCore {
self.eventLoop.execute {
self.removeHandlers(channel: self)
self.closePromise.succeed(())
self.multiplexer.childChannelClosed(streamID: self.streamID)
}
}
@@ -393,6 +397,7 @@ final class HTTP2StreamChannel: Channel, ChannelCore {
self.eventLoop.execute {
self.removeHandlers(channel: self)
self.closePromise.fail(error)
self.multiplexer.childChannelClosed(streamID: self.streamID)
}
}