diff --git a/Sources/NIO/BaseSocketChannel.swift b/Sources/NIO/BaseSocketChannel.swift index 0b2b337b5..6f329138a 100644 --- a/Sources/NIO/BaseSocketChannel.swift +++ b/Sources/NIO/BaseSocketChannel.swift @@ -802,9 +802,7 @@ class BaseSocketChannel: SelectableChannel, ChannelCore { registerPromise.futureResult.whenFailure { (_: Error) in self.close(promise: nil) } - if let promise = promise { - registerPromise.futureResult.cascadeFailure(promise: promise) - } + registerPromise.futureResult.cascadeFailure(promise: promise) if self.lifecycleManager.isPreRegistered { // we expect kqueue/epoll registration to always succeed which is basically true, except for errors that diff --git a/Sources/NIO/ChannelPipeline.swift b/Sources/NIO/ChannelPipeline.swift index eeaa7919f..56cab6503 100644 --- a/Sources/NIO/ChannelPipeline.swift +++ b/Sources/NIO/ChannelPipeline.swift @@ -395,9 +395,7 @@ public final class ChannelPipeline: ChannelInvoker { self.remove0(ctx: ctx, promise: promise) } - if let promise = promise { - contextFuture.cascadeFailure(promise: promise) - } + contextFuture.cascadeFailure(promise: promise) } /// Remove a `ChannelHandler` from the `ChannelPipeline`. @@ -412,9 +410,7 @@ public final class ChannelPipeline: ChannelInvoker { self.remove0(ctx: ctx, promise: promise) } - if let promise = promise { - contextFuture.cascadeFailure(promise: promise) - } + contextFuture.cascadeFailure(promise: promise) } /// Remove a `ChannelHandler` from the `ChannelPipeline`. diff --git a/Sources/NIO/EventLoopFuture.swift b/Sources/NIO/EventLoopFuture.swift index 412710eb6..eab576b90 100644 --- a/Sources/NIO/EventLoopFuture.swift +++ b/Sources/NIO/EventLoopFuture.swift @@ -749,7 +749,8 @@ extension EventLoopFuture { /// /// - parameters: /// - promise: The `EventLoopPromise` to fulfill with the results of this future. - public func cascade(promise: EventLoopPromise) { + public func cascade(promise: EventLoopPromise?) { + guard let promise = promise else { return } _whenCompleteWithValue { v in switch v { case .failure(let err): @@ -769,7 +770,8 @@ extension EventLoopFuture { /// /// - parameters: /// - promise: The `EventLoopPromise` to fulfill with the results of this future. - public func cascadeFailure(promise: EventLoopPromise) { + public func cascadeFailure(promise: EventLoopPromise?) { + guard let promise = promise else { return } self.whenFailure { err in promise.fail(error: err) } diff --git a/Sources/NIOHTTP1/HTTPResponseCompressor.swift b/Sources/NIOHTTP1/HTTPResponseCompressor.swift index 3738aec22..72c3aa78b 100644 --- a/Sources/NIOHTTP1/HTTPResponseCompressor.swift +++ b/Sources/NIOHTTP1/HTTPResponseCompressor.swift @@ -124,11 +124,11 @@ public final class HTTPResponseCompressor: ChannelDuplexHandler { responseHead.headers.replaceOrAdd(name: "Content-Encoding", value: algorithm!.rawValue) initializeEncoder(encoding: algorithm!) pendingResponse.bufferResponseHead(responseHead) - chainPromise(promise) + pendingWritePromise.futureResult.cascade(promise: promise) case .body(let body): if algorithm != nil { pendingResponse.bufferBodyPart(body) - chainPromise(promise) + pendingWritePromise.futureResult.cascade(promise: promise) } else { ctx.write(data, promise: promise) } @@ -141,7 +141,7 @@ public final class HTTPResponseCompressor: ChannelDuplexHandler { } pendingResponse.bufferResponseEnd(httpData) - chainPromise(promise) + pendingWritePromise.futureResult.cascade(promise: promise) emitPendingWrites(ctx: ctx) algorithm = nil deinitializeEncoder() @@ -212,12 +212,6 @@ public final class HTTPResponseCompressor: ChannelDuplexHandler { deflateEnd(&stream) } - private func chainPromise(_ promise: EventLoopPromise?) { - if let promise = promise { - pendingWritePromise.futureResult.cascade(promise: promise) - } - } - /// Emits all pending buffered writes to the network, optionally compressing the /// data. Resets the pending write buffer and promise. /// diff --git a/Sources/NIOHTTP1/HTTPServerPipelineHandler.swift b/Sources/NIOHTTP1/HTTPServerPipelineHandler.swift index 2e95256d3..91f922c1b 100644 --- a/Sources/NIOHTTP1/HTTPServerPipelineHandler.swift +++ b/Sources/NIOHTTP1/HTTPServerPipelineHandler.swift @@ -315,7 +315,7 @@ public final class HTTPServerPipelineHandler: ChannelDuplexHandler { case .quiescingLastRequestEndReceived: ctx.write(data).then { ctx.close() - }.cascade(promise: promise ?? ctx.channel.eventLoop.makePromise()) + }.cascade(promise: promise) case .acceptingEvents, .quiescingWaitingForRequestEnd: ctx.write(data, promise: promise) }