ChannelPipeline: addHandler and removeHandler instead of add/remove (#817)

Motivation:

- `ChannelPipeline.add(name:handler:...)` had a strange order of arguments
- `remove(handler:)` and `remove(ctx:)` both remove `ChannelHandler`s
  but they read like they remove different things

So let's just fix the argument order and name them `addHandler` and
`removeHandler` making clear what they do.

Modifications:

- rename all `ChannelPipeline.add(name:handler:...)`s to `ChannelPipeline.addHandler(_:name:...)`
- rename all `ChannelPipeline.remove(...)`s to `ChannelPipeline.removeHandler(...)`

Result:

more readable and consistent code
This commit is contained in:
Johannes Weiss authored and GitHub committed 2019-02-21 11:46:54 +00:00
1 parent 5d27e59bd9
commit 46ffd630de
50 files changed
+539 -425

No files matched your search

+4 -4
View File
@@ -207,7 +207,7 @@ public class HTTPServerUpgradeHandler: ChannelInboundHandler, RemovableChannelHa
ctx.fireChannelReadComplete()
}
}.whenComplete { (_: Result<Void, Error>) in
ctx.pipeline.remove(ctx: ctx, promise: nil)
ctx.pipeline.removeHandler(ctx: ctx, promise: nil)
}
}
}
@@ -226,7 +226,7 @@ public class HTTPServerUpgradeHandler: ChannelInboundHandler, RemovableChannelHa
private func notUpgrading(ctx: ChannelHandlerContext, data: NIOAny) {
assert(self.receivedMessages.count == 0)
ctx.fireChannelRead(data)
ctx.pipeline.remove(ctx: ctx, promise: nil)
ctx.pipeline.removeHandler(ctx: ctx, promise: nil)
}
/// Builds the initial mandatory HTTP headers for HTTP ugprade responses.
@@ -237,7 +237,7 @@ public class HTTPServerUpgradeHandler: ChannelInboundHandler, RemovableChannelHa
/// Removes the given channel handler from the channel pipeline.
private func removeHandler(ctx: ChannelHandlerContext, handler: RemovableChannelHandler?) -> EventLoopFuture<Void> {
if let handler = handler {
return ctx.pipeline.remove(handler: handler)
return ctx.pipeline.removeHandler(handler)
} else {
return ctx.eventLoop.makeSucceededFuture(())
}
@@ -249,7 +249,7 @@ public class HTTPServerUpgradeHandler: ChannelInboundHandler, RemovableChannelHa
return ctx.eventLoop.makeSucceededFuture(())
}
return .andAllSucceed(self.extraHTTPHandlers.map { ctx.pipeline.remove(handler: $0) },
return .andAllSucceed(self.extraHTTPHandlers.map { ctx.pipeline.removeHandler($0) },
on: ctx.eventLoop)
}
}