From b9c5535baf56979ef87f994c69f6a0e733ab70bc Mon Sep 17 00:00:00 2001 From: Tanner Date: Fri, 26 Apr 2019 19:26:07 -0400 Subject: [PATCH] publicize client's elg (#24) --- Sources/NIOHTTPClient/SwiftNIOHTTP.swift | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Sources/NIOHTTPClient/SwiftNIOHTTP.swift b/Sources/NIOHTTPClient/SwiftNIOHTTP.swift index baf8ce266..dffc5b195 100644 --- a/Sources/NIOHTTPClient/SwiftNIOHTTP.swift +++ b/Sources/NIOHTTPClient/SwiftNIOHTTP.swift @@ -24,19 +24,18 @@ public enum EventLoopGroupProvider { } public class HTTPClient { + public let eventLoopGroup: EventLoopGroup let eventLoopGroupProvider: EventLoopGroupProvider - let group: EventLoopGroup let configuration: Configuration - let isShutdown = Atomic(value: false) public init(eventLoopGroupProvider: EventLoopGroupProvider, configuration: Configuration = Configuration()) { self.eventLoopGroupProvider = eventLoopGroupProvider switch self.eventLoopGroupProvider { case .shared(let group): - self.group = group + self.eventLoopGroup = group case .createNew: - self.group = MultiThreadedEventLoopGroup(numberOfThreads: 1) + self.eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) } self.configuration = configuration } @@ -57,7 +56,7 @@ public class HTTPClient { return case .createNew: if self.isShutdown.compareAndExchange(expected: false, desired: true) { - try self.group.syncShutdownGracefully() + try self.eventLoopGroup.syncShutdownGracefully() } else { throw HTTPClientError.alreadyShutdown } @@ -69,7 +68,7 @@ public class HTTPClient { let request = try Request(url: url, method: .GET) return self.execute(request: request) } catch { - return self.group.next().makeFailedFuture(error) + return self.eventLoopGroup.next().makeFailedFuture(error) } } @@ -78,7 +77,7 @@ public class HTTPClient { let request = try HTTPClient.Request(url: url, method: .POST, body: body) return self.execute(request: request) } catch { - return self.group.next().makeFailedFuture(error) + return self.eventLoopGroup.next().makeFailedFuture(error) } } @@ -87,7 +86,7 @@ public class HTTPClient { let request = try HTTPClient.Request(url: url, method: .PATCH, body: body) return self.execute(request: request) } catch { - return self.group.next().makeFailedFuture(error) + return self.eventLoopGroup.next().makeFailedFuture(error) } } @@ -96,7 +95,7 @@ public class HTTPClient { let request = try HTTPClient.Request(url: url, method: .PUT, body: body) return self.execute(request: request) } catch { - return self.group.next().makeFailedFuture(error) + return self.eventLoopGroup.next().makeFailedFuture(error) } } @@ -105,7 +104,7 @@ public class HTTPClient { let request = try Request(url: url, method: .DELETE) return self.execute(request: request) } catch { - return self.group.next().makeFailedFuture(error) + return self.eventLoopGroup.next().makeFailedFuture(error) } } @@ -117,7 +116,7 @@ public class HTTPClient { public func execute(request: Request, delegate: T, timeout: Timeout? = nil) -> Task { let timeout = timeout ?? configuration.timeout - let promise: EventLoopPromise = group.next().makePromise() + let promise: EventLoopPromise = self.eventLoopGroup.next().makePromise() let redirectHandler: RedirectHandler? if self.configuration.followRedirects { @@ -130,7 +129,7 @@ public class HTTPClient { let task = Task(future: promise.futureResult) - var bootstrap = ClientBootstrap(group: group) + var bootstrap = ClientBootstrap(group: self.eventLoopGroup) .channelOption(ChannelOptions.socket(SocketOptionLevel(IPPROTO_TCP), TCP_NODELAY), value: 1) .channelInitializer { channel in let encoder = HTTPRequestEncoder()