diff --git a/Sources/NIO/ChannelPipeline.swift b/Sources/NIO/ChannelPipeline.swift index bf2f25305..4a527ddbe 100644 --- a/Sources/NIO/ChannelPipeline.swift +++ b/Sources/NIO/ChannelPipeline.swift @@ -210,7 +210,7 @@ public final class ChannelPipeline : ChannelInvoker { let promise: EventLoopPromise = self.eventLoop.newPromise() context0({ return $0.handler === handler - }).then { ctx in + }).map { ctx in self.remove0(ctx: ctx, promise: promise) }.cascadeFailure(promise: promise) return promise.futureResult @@ -223,7 +223,7 @@ public final class ChannelPipeline : ChannelInvoker { /// - returns: the `EventLoopFuture` which will be notified once the `ChannelHandler` was removed. public func remove(name: String) -> EventLoopFuture { let promise: EventLoopPromise = self.eventLoop.newPromise() - context0({ $0.name == name }).then { ctx in + context0({ $0.name == name }).map { ctx in self.remove0(ctx: ctx, promise: promise) }.cascadeFailure(promise: promise) return promise.futureResult diff --git a/Sources/NIO/EventLoopFuture.swift b/Sources/NIO/EventLoopFuture.swift index 66ed04580..58e37996c 100644 --- a/Sources/NIO/EventLoopFuture.swift +++ b/Sources/NIO/EventLoopFuture.swift @@ -384,7 +384,7 @@ extension EventLoopFuture { Generally, a simple closure provided to `then()` should never block. If you need to do something time-consuming, your closure can schedule the operation on another queue and return another `EventLoopFuture<>` object instead. See `then(queue:callback:)` for a convenient way to do this. */ - public func then(file: StaticString = #file, line: UInt = #line, callback: @escaping (T) throws -> (U)) -> EventLoopFuture { + public func map(file: StaticString = #file, line: UInt = #line, callback: @escaping (T) throws -> (U)) -> EventLoopFuture { return then { return EventLoopFuture(eventLoop: self.eventLoop, result: try callback($0), file: file, line: line) } } @@ -426,7 +426,7 @@ extension EventLoopFuture { return next.futureResult } - public func thenIfError(file: StaticString = #file, line: UInt = #line, callback: @escaping (Error) throws -> T) -> EventLoopFuture { + public func mapIfError(file: StaticString = #file, line: UInt = #line, callback: @escaping (Error) throws -> T) -> EventLoopFuture { return thenIfError { return EventLoopFuture(eventLoop: self.eventLoop, result: try callback($0), file: file, line: line) } } @@ -605,7 +605,7 @@ extension EventLoopFuture { return p0.futureResult } - let fn: EventLoopFuture = futures.reduce(p0.futureResult, { (f1: EventLoopFuture, f2: EventLoopFuture) in f1.and(f2).then(callback: { _ in return () }) }) + let fn: EventLoopFuture = futures.reduce(p0.futureResult, { (f1: EventLoopFuture, f2: EventLoopFuture) in f1.and(f2).map(callback: { _ in return () }) }) p0.succeed(result: ()) return fn } diff --git a/Sources/NIOHTTP1/HTTPEncoder.swift b/Sources/NIOHTTP1/HTTPEncoder.swift index 68a46975b..e833faf93 100644 --- a/Sources/NIOHTTP1/HTTPEncoder.swift +++ b/Sources/NIOHTTP1/HTTPEncoder.swift @@ -22,7 +22,7 @@ private func writeChunk(wrapOutboundOut: (IOData) -> NIOAny, ctx: ChannelHandler case (true, .some(let p)): /* chunked encoding and the user's interested: we need three promises and need to cascade into the users promise */ let (w1, w2, w3) = (ctx.eventLoop.newPromise() as EventLoopPromise<()>, ctx.eventLoop.newPromise() as EventLoopPromise<()>, ctx.eventLoop.newPromise() as EventLoopPromise<()>) - w1.futureResult.and(w2.futureResult).and(w3.futureResult).then { _ in () }.cascade(promise: p) + w1.futureResult.and(w2.futureResult).and(w3.futureResult).map { _ in () }.cascade(promise: p) (mW1, mW2, mW3) = (w1, w2, w3) case (false, .some(let p)): /* not chunked, so just use the user's promise for the actual data */ diff --git a/Sources/NIOTLS/SNIHandler.swift b/Sources/NIOTLS/SNIHandler.swift index 6f261cce3..21341bbc4 100644 --- a/Sources/NIOTLS/SNIHandler.swift +++ b/Sources/NIOTLS/SNIHandler.swift @@ -402,7 +402,7 @@ public class SniHandler: ByteToMessageDecoder { private func sniComplete(result: SniResult, ctx: ChannelHandlerContext) { waitingForUser = true _ = completionHandler(result).then { - ctx.pipeline?.remove(handler: self) + ctx.pipeline!.remove(handler: self) } } } diff --git a/Tests/NIOTests/ChannelTests.swift b/Tests/NIOTests/ChannelTests.swift index f02895417..0f3131758 100644 --- a/Tests/NIOTests/ChannelTests.swift +++ b/Tests/NIOTests/ChannelTests.swift @@ -95,7 +95,7 @@ public class ChannelTests: XCTestCase { try clientChannel.close().wait() // Wait for the close promises. These fire last. - try EventLoopFuture.andAll([clientChannel.closeFuture, serverAcceptedChannel!.closeFuture], eventLoop: group.next()).then { _ in + try EventLoopFuture.andAll([clientChannel.closeFuture, serverAcceptedChannel!.closeFuture], eventLoop: group.next()).map { _ in XCTAssertEqual(clientLifecycleHandler.currentState, .unregistered) XCTAssertEqual(serverLifecycleHandler.currentState, .unregistered) XCTAssertEqual(clientLifecycleHandler.stateHistory, [.unregistered, .inactive, .active, .inactive, .unregistered])