remove ugly and unnecessary ignore result (_ = ...) (#652)

Motivation:

_ = expression() is ugly and in many cases unimportant. In fact we train
ourselves to overread it which makes special cases where you'd actually
expect a result to be used just look normal.

Modifications:

remove _ = from a lot of places. In many cases we already had a better
(and sometimes cheaper way) to not return a value but in some cases
(mostly `remove` functions) I added `@discardableResult`

Result:

NIO source code looks nicer
This commit is contained in:
Johannes Weiss authored and GitHub committed 2018-11-13 14:49:08 +00:00
1 parent a0b3b19cf4
commit 08ab8b51cd
19 files changed
+74 -62

No files matched your search

+4 -4
View File
@@ -215,7 +215,7 @@ public class HTTPServerUpgradeHandler: ChannelInboundHandler {
// internal handler, then call the user code, and then finally when the user code is done we do
// our final cleanup steps, namely we replay the received data we buffered in the meantime and
// then remove ourselves from the pipeline.
_ = self.removeExtraHandlers(ctx: ctx).then {
self.removeExtraHandlers(ctx: ctx).then {
self.sendUpgradeResponse(ctx: ctx, upgradeRequest: request, responseHeaders: responseHeaders)
}.then {
self.removeHandler(ctx: ctx, handler: self.httpEncoder)
@@ -236,8 +236,8 @@ public class HTTPServerUpgradeHandler: ChannelInboundHandler {
if bufferedMessages.count > 0 {
ctx.fireChannelReadComplete()
}
}.then {
ctx.pipeline.remove(ctx: ctx)
}.whenComplete {
ctx.pipeline.remove(ctx: ctx, promise: nil)
}
}
}
@@ -256,7 +256,7 @@ public class HTTPServerUpgradeHandler: ChannelInboundHandler {
private func notUpgrading(ctx: ChannelHandlerContext, data: NIOAny) {
assert(self.receivedMessages.count == 0)
ctx.fireChannelRead(data)
_ = ctx.pipeline.remove(ctx: ctx)
ctx.pipeline.remove(ctx: ctx, promise: nil)
}
/// Builds the initial mandatory HTTP headers for HTTP ugprade responses.