Closed funcmike closed 1 year ago
New handler proposal
protocol AMPQChannelHandlerParent { func write(payload: Payload, promise: EventLoopPromise<Void>?) } final class AMPQFrameHandler { var channels: [ChannelID: AMPQChannelHandler<Self>] var context: ChannelHandlerContext! func handlerAdded(context: ChannelHandlerContext) { self.context = context } func handlerRemoved(context: ChannelHandlerContext) { self.context = nil } func openChannel() -> EventLoopFuture<AMPQChannelHandler<Self>> { let nextChannelID = ... // sendMessage to create channel // when done create AMPQChannelHandler with ChannelID } } extension AMPQFrameHandler: AMPQChannelHandlerParent { func write(frame: Frame, promise: EventLoopPromise<Void>?) { // write into the channel pipeline using self.context } } final class AMPQChannelHandler<Parent: AMPQChannelHandlerParent> { let parent: Parent let eventLoop: EventLoop init(parent: Parent, channelID: ChannelID, eventLoop: EventLoop) { self.parent = parent } func send(payload: Payload) -> EventLoopFuture<Response> { let frame = Frame(channelID: self.channelID, payload: Payload) self.parent.write(frame: frame) } func receive(payload: Payload) { } }
New handler proposal