Navigation Menu

Skip to content

Commit

Permalink
EventLoopFuture: use Result type (#734)
Browse files Browse the repository at this point in the history
Motivation:

Now that the stdlib has introduced the Result type, we can use it in the
implementation (and the whenComplete) function of EventLoopFuture

Modifications:

- replace EventLoopValue with Result
- make whenComplete provide the Result

Result:

use the new shiny stuff
  • Loading branch information
weissi authored and Lukasa committed Jan 5, 2019
1 parent 08eb325 commit 684cad3
Show file tree
Hide file tree
Showing 21 changed files with 74 additions and 86 deletions.
2 changes: 1 addition & 1 deletion Sources/NIO/Bootstrap.swift
Expand Up @@ -440,7 +440,7 @@ public final class ClientBootstrap {
channel.close(promise: nil) channel.close(promise: nil)
} }


connectPromise.futureResult.whenComplete { connectPromise.futureResult.whenComplete { (_: Result<Void, Error>) in
cancelTask.cancel() cancelTask.cancel()
} }
return connectPromise.futureResult return connectPromise.futureResult
Expand Down
2 changes: 1 addition & 1 deletion Sources/NIO/ChannelHandlers.swift
Expand Up @@ -223,7 +223,7 @@ public class IdleStateHandler: ChannelDuplexHandler {
} }


let writePromise = promise ?? ctx.eventLoop.makePromise() let writePromise = promise ?? ctx.eventLoop.makePromise()
writePromise.futureResult.whenComplete { writePromise.futureResult.whenComplete { (_: Result<Void, Error>) in
self.lastWriteCompleteTime = DispatchTime.now() self.lastWriteCompleteTime = DispatchTime.now()
} }
ctx.write(data, promise: writePromise) ctx.write(data, promise: writePromise)
Expand Down
4 changes: 2 additions & 2 deletions Sources/NIO/EventLoop.swift
Expand Up @@ -116,7 +116,7 @@ public final class RepeatedTask {
} }


scheduled.futureResult.whenSuccess { future in scheduled.futureResult.whenSuccess { future in
future.whenComplete { future.whenComplete { (_: Result<Void, Error>) in
self.reschedule0() self.reschedule0()
} }
} }
Expand Down Expand Up @@ -957,7 +957,7 @@ final public class MultiThreadedEventLoopGroup: EventLoopGroup {
g.enter() g.enter()
loop.closeGently().mapIfError { err in loop.closeGently().mapIfError { err in
q.sync { error = err } q.sync { error = err }
}.whenComplete { }.whenComplete { (_: Result<Void, Error>) in
g.leave() g.leave()
} }
} }
Expand Down
26 changes: 9 additions & 17 deletions Sources/NIO/EventLoopFuture.swift
Expand Up @@ -14,14 +14,6 @@


import NIOConcurrencyHelpers import NIOConcurrencyHelpers



/// A `Result`-like type that is used to track the data through the
/// callback pipeline.
private enum EventLoopFutureValue<T> {
case success(T)
case failure(Error)
}

/// Internal list of callbacks. /// Internal list of callbacks.
/// ///
/// Most of these are closures that pull a value from one future, call a user callback, push the /// Most of these are closures that pull a value from one future, call a user callback, push the
Expand Down Expand Up @@ -187,7 +179,7 @@ public struct EventLoopPromise<T> {
/// ///
/// - parameters: /// - parameters:
/// - value: The value to fire the future with. /// - value: The value to fire the future with.
private func _resolve(value: EventLoopFutureValue<T>) { private func _resolve(value: Result<T, Error>) {
if futureResult.eventLoop.inEventLoop { if futureResult.eventLoop.inEventLoop {
_setValue(value: value)._run() _setValue(value: value)._run()
} else { } else {
Expand All @@ -202,7 +194,7 @@ public struct EventLoopPromise<T> {
/// - parameters: /// - parameters:
/// - value: The result of the promise. /// - value: The result of the promise.
/// - returns: The callback list to run. /// - returns: The callback list to run.
fileprivate func _setValue(value: EventLoopFutureValue<T>) -> CallbackList { fileprivate func _setValue(value: Result<T, Error>) -> CallbackList {
return futureResult._setValue(value: value) return futureResult._setValue(value: value)
} }
} }
Expand Down Expand Up @@ -333,7 +325,7 @@ public struct EventLoopPromise<T> {
/// `EventLoopFuture` should be sufficient to guarantee thread-safety. /// `EventLoopFuture` should be sufficient to guarantee thread-safety.
public final class EventLoopFuture<T> { public final class EventLoopFuture<T> {
// TODO: Provide a tracing facility. It would be nice to be able to set '.debugTrace = true' on any EventLoopFuture or EventLoopPromise and have every subsequent chained EventLoopFuture report the success result or failure error. That would simplify some debugging scenarios. // TODO: Provide a tracing facility. It would be nice to be able to set '.debugTrace = true' on any EventLoopFuture or EventLoopPromise and have every subsequent chained EventLoopFuture report the success result or failure error. That would simplify some debugging scenarios.
fileprivate var value: EventLoopFutureValue<T>? { fileprivate var value: Result<T, Error>? {
didSet { didSet {
_isFulfilled.store(true) _isFulfilled.store(true)
} }
Expand All @@ -356,7 +348,7 @@ public final class EventLoopFuture<T> {
/// the entire chain from the top without recursing. /// the entire chain from the top without recursing.
fileprivate var callbacks: CallbackList = CallbackList() fileprivate var callbacks: CallbackList = CallbackList()


private init(eventLoop: EventLoop, value: EventLoopFutureValue<T>?, file: StaticString, line: UInt) { private init(eventLoop: EventLoop, value: Result<T, Error>?, file: StaticString, line: UInt) {
self.eventLoop = eventLoop self.eventLoop = eventLoop
self.value = value self.value = value
self._isFulfilled = UnsafeEmbeddedAtomic(value: value != nil) self._isFulfilled = UnsafeEmbeddedAtomic(value: value != nil)
Expand Down Expand Up @@ -608,7 +600,7 @@ extension EventLoopFuture {
} }
} }


fileprivate func _whenCompleteWithValue(_ callback: @escaping (EventLoopFutureValue<T>) -> Void) { fileprivate func _whenCompleteWithValue(_ callback: @escaping (Result<T, Error>) -> Void) {
_whenComplete { _whenComplete {
callback(self.value!) callback(self.value!)
return CallbackList() return CallbackList()
Expand Down Expand Up @@ -662,16 +654,16 @@ extension EventLoopFuture {
/// ///
/// - parameters: /// - parameters:
/// - callback: The callback that is called when the `EventLoopFuture` is fulfilled. /// - callback: The callback that is called when the `EventLoopFuture` is fulfilled.
public func whenComplete(_ callback: @escaping () -> Void) { public func whenComplete(_ callback: @escaping (Result<T, Error>) -> Void) {
_whenComplete { _whenComplete {
callback() callback(self.value!)
return CallbackList() return CallbackList()
} }
} }




/// Internal: Set the value and return a list of callbacks that should be invoked as a result. /// Internal: Set the value and return a list of callbacks that should be invoked as a result.
fileprivate func _setValue(value: EventLoopFutureValue<T>) -> CallbackList { fileprivate func _setValue(value: Result<T, Error>) -> CallbackList {
self.eventLoop.assertInEventLoop() self.eventLoop.assertInEventLoop()
if self.value == nil { if self.value == nil {
self.value = value self.value = value
Expand Down Expand Up @@ -813,7 +805,7 @@ Further information:
precondition(MultiThreadedEventLoopGroup.currentEventLoop == nil, explainer(), file: file, line: line) precondition(MultiThreadedEventLoopGroup.currentEventLoop == nil, explainer(), file: file, line: line)
} }


var v: EventLoopFutureValue <T>? = nil var v: Result<T, Error>? = nil
let lock = ConditionLock(value: 0) let lock = ConditionLock(value: 0)
_whenComplete { () -> CallbackList in _whenComplete { () -> CallbackList in
lock.lock() lock.lock()
Expand Down
4 changes: 2 additions & 2 deletions Sources/NIO/HappyEyeballs.swift
Expand Up @@ -606,7 +606,7 @@ internal class HappyEyeballsConnector {
self.targets.aResultsAvailable(results) self.targets.aResultsAvailable(results)
}.mapIfError { err in }.mapIfError { err in
self.error.dnsAError = err self.error.dnsAError = err
}.whenComplete { }.whenComplete { (_: Result<Void, Error>) in
self.dnsResolutions += 1 self.dnsResolutions += 1
self.processInput(.resolverACompleted) self.processInput(.resolverACompleted)
} }
Expand All @@ -618,7 +618,7 @@ internal class HappyEyeballsConnector {
self.targets.aaaaResultsAvailable(results) self.targets.aaaaResultsAvailable(results)
}.mapIfError { err in }.mapIfError { err in
self.error.dnsAAAAError = err self.error.dnsAAAAError = err
}.whenComplete { }.whenComplete { (_: Result<Void, Error>) in
// It's possible that we were waiting to time out here, so if we were we should // It's possible that we were waiting to time out here, so if we were we should
// cancel that. // cancel that.
self.resolutionTask?.cancel() self.resolutionTask?.cancel()
Expand Down
2 changes: 1 addition & 1 deletion Sources/NIOHTTP1/HTTPUpgradeHandler.swift
Expand Up @@ -206,7 +206,7 @@ public class HTTPServerUpgradeHandler: ChannelInboundHandler {
if bufferedMessages.count > 0 { if bufferedMessages.count > 0 {
ctx.fireChannelReadComplete() ctx.fireChannelReadComplete()
} }
}.whenComplete { }.whenComplete { (_: Result<Void, Error>) in
ctx.pipeline.remove(ctx: ctx, promise: nil) ctx.pipeline.remove(ctx: ctx, promise: nil)
} }
} }
Expand Down
6 changes: 3 additions & 3 deletions Sources/NIOHTTP1Server/main.swift
Expand Up @@ -358,7 +358,7 @@ private final class HTTPHandler: ChannelInboundHandler {
} else { } else {
return ctx.close() return ctx.close()
} }
}.whenComplete { }.whenComplete { (_: Result<Void, Error>) in
_ = try? file.close() _ = try? file.close()
} }
case .sendfile: case .sendfile:
Expand All @@ -370,7 +370,7 @@ private final class HTTPHandler: ChannelInboundHandler {
return p.futureResult return p.futureResult
}.thenIfError { (_: Error) in }.thenIfError { (_: Error) in
ctx.close() ctx.close()
}.whenComplete { }.whenComplete { (_: Result<Void, Error>) in
_ = try? file.close() _ = try? file.close()
} }
} }
Expand All @@ -387,7 +387,7 @@ private final class HTTPHandler: ChannelInboundHandler {


let promise = self.keepAlive ? promise : (promise ?? ctx.eventLoop.makePromise()) let promise = self.keepAlive ? promise : (promise ?? ctx.eventLoop.makePromise())
if !self.keepAlive { if !self.keepAlive {
promise!.futureResult.whenComplete { ctx.close(promise: nil) } promise!.futureResult.whenComplete { (_: Result<Void, Error>) in ctx.close(promise: nil) }
} }
self.handler = nil self.handler = nil


Expand Down
2 changes: 1 addition & 1 deletion Sources/NIOTLS/ApplicationProtocolNegotiationHandler.swift
Expand Up @@ -118,7 +118,7 @@ public class ApplicationProtocolNegotiationHandler: ChannelInboundHandler {
} }


let switchFuture = completionHandler(result) let switchFuture = completionHandler(result)
switchFuture.whenComplete { switchFuture.whenComplete { (_: Result<Void, Error>) in
self.unbuffer(context: context) self.unbuffer(context: context)
context.pipeline.remove(handler: self, promise: nil) context.pipeline.remove(handler: self, promise: nil)
} }
Expand Down
2 changes: 1 addition & 1 deletion Sources/NIOWebSocket/WebSocketFrameDecoder.swift
Expand Up @@ -309,7 +309,7 @@ public final class WebSocketFrameDecoder: ByteToMessageDecoder {
let frame = WebSocketFrame(fin: true, let frame = WebSocketFrame(fin: true,
opcode: .connectionClose, opcode: .connectionClose,
data: data) data: data)
ctx.writeAndFlush(self.wrapInboundOut(frame)).whenComplete { ctx.writeAndFlush(self.wrapInboundOut(frame)).whenComplete { (_: Result<Void, Error>) in
ctx.close(promise: nil) ctx.close(promise: nil)
} }
} }
Expand Down
2 changes: 1 addition & 1 deletion Sources/NIOWebSocket/WebSocketProtocolErrorHandler.swift
Expand Up @@ -32,7 +32,7 @@ public final class WebSocketProtocolErrorHandler: ChannelInboundHandler {
let frame = WebSocketFrame(fin: true, let frame = WebSocketFrame(fin: true,
opcode: .connectionClose, opcode: .connectionClose,
data: data) data: data)
ctx.writeAndFlush(self.wrapOutboundOut(frame)).whenComplete { ctx.writeAndFlush(self.wrapOutboundOut(frame)).whenComplete { (_: Result<Void, Error>) in
ctx.close(promise: nil) ctx.close(promise: nil)
} }
} }
Expand Down
6 changes: 3 additions & 3 deletions Sources/NIOWebSocketServer/main.swift
Expand Up @@ -81,7 +81,7 @@ private final class HTTPHandler: ChannelInboundHandler {
headers: headers) headers: headers)
ctx.write(self.wrapOutboundOut(.head(responseHead)), promise: nil) ctx.write(self.wrapOutboundOut(.head(responseHead)), promise: nil)
ctx.write(self.wrapOutboundOut(.body(.byteBuffer(self.responseBody))), promise: nil) ctx.write(self.wrapOutboundOut(.body(.byteBuffer(self.responseBody))), promise: nil)
ctx.write(self.wrapOutboundOut(.end(nil))).whenComplete { ctx.write(self.wrapOutboundOut(.end(nil))).whenComplete { (_: Result<Void, Error>) in
ctx.close(promise: nil) ctx.close(promise: nil)
} }
ctx.flush() ctx.flush()
Expand All @@ -95,7 +95,7 @@ private final class HTTPHandler: ChannelInboundHandler {
status: .methodNotAllowed, status: .methodNotAllowed,
headers: headers) headers: headers)
ctx.write(self.wrapOutboundOut(.head(head)), promise: nil) ctx.write(self.wrapOutboundOut(.head(head)), promise: nil)
ctx.write(self.wrapOutboundOut(.end(nil))).whenComplete { ctx.write(self.wrapOutboundOut(.end(nil))).whenComplete { (_: Result<Void, Error>) in
ctx.close(promise: nil) ctx.close(promise: nil)
} }
ctx.flush() ctx.flush()
Expand Down Expand Up @@ -194,7 +194,7 @@ private final class WebSocketTimeHandler: ChannelInboundHandler {
var data = ctx.channel.allocator.buffer(capacity: 2) var data = ctx.channel.allocator.buffer(capacity: 2)
data.write(webSocketErrorCode: .protocolError) data.write(webSocketErrorCode: .protocolError)
let frame = WebSocketFrame(fin: true, opcode: .connectionClose, data: data) let frame = WebSocketFrame(fin: true, opcode: .connectionClose, data: data)
ctx.write(self.wrapOutboundOut(frame)).whenComplete { ctx.write(self.wrapOutboundOut(frame)).whenComplete { (_: Result<Void, Error>) in
ctx.close(mode: .output, promise: nil) ctx.close(mode: .output, promise: nil)
} }
awaitingClose = true awaitingClose = true
Expand Down
2 changes: 1 addition & 1 deletion Tests/NIOHTTP1Tests/HTTPResponseCompressorTest.swift
Expand Up @@ -36,7 +36,7 @@ private class PromiseOrderer {
let thisPromiseIndex = promiseArray.count let thisPromiseIndex = promiseArray.count
promiseArray.append(promise) promiseArray.append(promise)


promise.futureResult.whenComplete { promise.futureResult.whenComplete { (_: Result<Void, Error>) in
let priorFutures = self.promiseArray[0..<thisPromiseIndex] let priorFutures = self.promiseArray[0..<thisPromiseIndex]
let subsequentFutures = self.promiseArray[(thisPromiseIndex + 1)...] let subsequentFutures = self.promiseArray[(thisPromiseIndex + 1)...]
let allPriorFuturesFired = priorFutures.map { $0.futureResult.isFulfilled }.allSatisfy { $0 } let allPriorFuturesFired = priorFutures.map { $0.futureResult.isFulfilled }.allSatisfy { $0 }
Expand Down
20 changes: 10 additions & 10 deletions Tests/NIOHTTP1Tests/HTTPServerClientTest.swift
Expand Up @@ -124,12 +124,12 @@ class HTTPServerClientTest : XCTestCase {
b.write(string: replyString) b.write(string: replyString)


let outbound = self.outboundBody(b) let outbound = self.outboundBody(b)
ctx.write(self.wrapOutboundOut(outbound.body)).whenComplete { ctx.write(self.wrapOutboundOut(outbound.body)).whenComplete { (_: Result<Void, Error>) in
outbound.destructor() outbound.destructor()
} }
ctx.write(self.wrapOutboundOut(.end(nil))).mapIfError { error in ctx.write(self.wrapOutboundOut(.end(nil))).mapIfError { error in
XCTFail("unexpected error \(error)") XCTFail("unexpected error \(error)")
}.whenComplete { }.whenComplete { (_: Result<Void, Error>) in
self.sentEnd = true self.sentEnd = true
self.maybeClose(ctx: ctx) self.maybeClose(ctx: ctx)
} }
Expand All @@ -148,13 +148,13 @@ class HTTPServerClientTest : XCTestCase {
let outbound = self.outboundBody(b) let outbound = self.outboundBody(b)
ctx.write(self.wrapOutboundOut(outbound.body)).mapIfError { error in ctx.write(self.wrapOutboundOut(outbound.body)).mapIfError { error in
XCTFail("unexpected error \(error)") XCTFail("unexpected error \(error)")
}.whenComplete { }.whenComplete { (_: Result<Void, Error>) in
outbound.destructor() outbound.destructor()
} }
} }
ctx.write(self.wrapOutboundOut(.end(nil))).mapIfError { error in ctx.write(self.wrapOutboundOut(.end(nil))).mapIfError { error in
XCTFail("unexpected error \(error)") XCTFail("unexpected error \(error)")
}.whenComplete { }.whenComplete { (_: Result<Void, Error>) in
self.sentEnd = true self.sentEnd = true
self.maybeClose(ctx: ctx) self.maybeClose(ctx: ctx)
} }
Expand All @@ -174,7 +174,7 @@ class HTTPServerClientTest : XCTestCase {
let outbound = self.outboundBody(b) let outbound = self.outboundBody(b)
ctx.write(self.wrapOutboundOut(outbound.body)).mapIfError { error in ctx.write(self.wrapOutboundOut(outbound.body)).mapIfError { error in
XCTFail("unexpected error \(error)") XCTFail("unexpected error \(error)")
}.whenComplete { }.whenComplete { (_: Result<Void, Error>) in
outbound.destructor() outbound.destructor()
} }
} }
Expand All @@ -184,7 +184,7 @@ class HTTPServerClientTest : XCTestCase {
trailers.add(name: "X-Should-Trail", value: "sure") trailers.add(name: "X-Should-Trail", value: "sure")
ctx.write(self.wrapOutboundOut(.end(trailers))).mapIfError { error in ctx.write(self.wrapOutboundOut(.end(trailers))).mapIfError { error in
XCTFail("unexpected error \(error)") XCTFail("unexpected error \(error)")
}.whenComplete { }.whenComplete { (_: Result<Void, Error>) in
self.sentEnd = true self.sentEnd = true
self.maybeClose(ctx: ctx) self.maybeClose(ctx: ctx)
} }
Expand All @@ -209,12 +209,12 @@ class HTTPServerClientTest : XCTestCase {
let outbound = self.outboundBody(buf) let outbound = self.outboundBody(buf)
ctx.writeAndFlush(self.wrapOutboundOut(outbound.body)).mapIfError { error in ctx.writeAndFlush(self.wrapOutboundOut(outbound.body)).mapIfError { error in
XCTFail("unexpected error \(error)") XCTFail("unexpected error \(error)")
}.whenComplete { }.whenComplete { (_: Result<Void, Error>) in
outbound.destructor() outbound.destructor()
} }
ctx.write(self.wrapOutboundOut(.end(nil))).mapIfError { error in ctx.write(self.wrapOutboundOut(.end(nil))).mapIfError { error in
XCTFail("unexpected error \(error)") XCTFail("unexpected error \(error)")
}.whenComplete { }.whenComplete { (_: Result<Void, Error>) in
self.sentEnd = true self.sentEnd = true
self.maybeClose(ctx: ctx) self.maybeClose(ctx: ctx)
} }
Expand All @@ -227,7 +227,7 @@ class HTTPServerClientTest : XCTestCase {
} }
ctx.write(self.wrapOutboundOut(.end(nil))).mapIfError { error in ctx.write(self.wrapOutboundOut(.end(nil))).mapIfError { error in
XCTFail("unexpected error \(error)") XCTFail("unexpected error \(error)")
}.whenComplete { }.whenComplete { (_: Result<Void, Error>) in
self.sentEnd = true self.sentEnd = true
self.maybeClose(ctx: ctx) self.maybeClose(ctx: ctx)
} }
Expand All @@ -239,7 +239,7 @@ class HTTPServerClientTest : XCTestCase {
} }
ctx.write(self.wrapOutboundOut(.end(nil))).mapIfError { error in ctx.write(self.wrapOutboundOut(.end(nil))).mapIfError { error in
XCTFail("unexpected error \(error)") XCTFail("unexpected error \(error)")
}.whenComplete { }.whenComplete { (_: Result<Void, Error>) in
self.sentEnd = true self.sentEnd = true
self.maybeClose(ctx: ctx) self.maybeClose(ctx: ctx)
} }
Expand Down
2 changes: 1 addition & 1 deletion Tests/NIOTests/ChannelTests.swift
Expand Up @@ -972,7 +972,7 @@ public class ChannelTests: XCTestCase {
pwm.markFlushCheckpoint() pwm.markFlushCheckpoint()
_ = pwm.add(data: .byteBuffer(buffer), promise: ps[2]) _ = pwm.add(data: .byteBuffer(buffer), promise: ps[2])


ps[0].futureResult.whenComplete { ps[0].futureResult.whenComplete { (_: Result<Void, Error>) in
pwm.failAll(error: ChannelError.inputClosed, close: true) pwm.failAll(error: ChannelError.inputClosed, close: true)
} }


Expand Down
8 changes: 4 additions & 4 deletions Tests/NIOTests/EchoServerClientTest.swift
Expand Up @@ -350,7 +350,7 @@ class EchoServerClientTest : XCTestCase {
default: default:
XCTFail("unexpected error: \(err)") XCTFail("unexpected error: \(err)")
} }
}.whenComplete { }.whenComplete { (_: Result<Void, Error>) in
self.channelInactivePromise.succeed(result: ()) self.channelInactivePromise.succeed(result: ())
} }
} }
Expand All @@ -370,7 +370,7 @@ class EchoServerClientTest : XCTestCase {
default: default:
XCTFail("unexpected error: \(err)") XCTFail("unexpected error: \(err)")
} }
}.whenComplete { }.whenComplete { (_: Result<Void, Error>) in
self.channelUnregisteredPromise.succeed(result: ()) self.channelUnregisteredPromise.succeed(result: ())
} }
} }
Expand Down Expand Up @@ -603,7 +603,7 @@ class EchoServerClientTest : XCTestCase {
} }


private func writeUntilFailed(_ ctx: ChannelHandlerContext, _ buffer: ByteBuffer) { private func writeUntilFailed(_ ctx: ChannelHandlerContext, _ buffer: ByteBuffer) {
ctx.writeAndFlush(NIOAny(buffer)).whenComplete { ctx.writeAndFlush(NIOAny(buffer)).whenComplete { (_: Result<Void, Error>) in
ctx.eventLoop.execute { ctx.eventLoop.execute {
self.writeUntilFailed(ctx, buffer) self.writeUntilFailed(ctx, buffer)
} }
Expand Down Expand Up @@ -635,7 +635,7 @@ class EchoServerClientTest : XCTestCase {
ctx.writeAndFlush(NIOAny(buffer)) ctx.writeAndFlush(NIOAny(buffer))
}.then { }.then {
ctx.close() ctx.close()
}.whenComplete { }.whenComplete { (_: Result<Void, Error>) in
self.dpGroup.leave() self.dpGroup.leave()
} }
} }
Expand Down
4 changes: 2 additions & 2 deletions Tests/NIOTests/EmbeddedChannelTest.swift
Expand Up @@ -160,14 +160,14 @@ class EmbeddedChannelTest: XCTestCase {
let channel = EmbeddedChannel() let channel = EmbeddedChannel()
XCTAssertFalse(channel.isActive) XCTAssertFalse(channel.isActive)
let connectPromise = channel.eventLoop.makePromise(of: Void.self) let connectPromise = channel.eventLoop.makePromise(of: Void.self)
connectPromise.futureResult.whenComplete { connectPromise.futureResult.whenComplete { (_: Result<Void, Error>) in
XCTAssertTrue(channel.isActive) XCTAssertTrue(channel.isActive)
} }
channel.connect(to: try SocketAddress(ipAddress: "127.0.0.1", port: 0), promise: connectPromise) channel.connect(to: try SocketAddress(ipAddress: "127.0.0.1", port: 0), promise: connectPromise)
try connectPromise.futureResult.wait() try connectPromise.futureResult.wait()


let closePromise = channel.eventLoop.makePromise(of: Void.self) let closePromise = channel.eventLoop.makePromise(of: Void.self)
closePromise.futureResult.whenComplete { closePromise.futureResult.whenComplete { (_: Result<Void, Error>) in
XCTAssertFalse(channel.isActive) XCTAssertFalse(channel.isActive)
} }


Expand Down
2 changes: 1 addition & 1 deletion Tests/NIOTests/EmbeddedEventLoopTest.swift
Expand Up @@ -215,7 +215,7 @@ public class EmbeddedEventLoopTest: XCTestCase {
XCTFail("Scheduled future completed") XCTFail("Scheduled future completed")
}.mapIfError { caughtErr in }.mapIfError { caughtErr in
XCTAssertTrue(err === caughtErr as? EmbeddedTestError) XCTAssertTrue(err === caughtErr as? EmbeddedTestError)
}.whenComplete { }.whenComplete { (_: Result<Void, Error>) in
fired = true fired = true
} }


Expand Down

0 comments on commit 684cad3

Please sign in to comment.