make ELF.cascade accept an optional promise (#757)

* Make EventLoopFuture.cascade and cascadeFailure accept an optional promise

Motivation:

fixes #756

Modifications:

Change EventLoopFuture.cascade to func cascade(promise: EventLoopPromise<T>?)

Result:

EventLoopFuture.cascade can be called without needing to check if the promise is nil
This commit is contained in:
David Skrundz authored and Johannes Weiss committed 2019-01-19 13:59:12 +00:00
1 parent f50230aeba
commit f7357e66ab
5 files changed
+11 -21

No files matched your search

@@ -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<Void>?) {
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.
///
@@ -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)
}