Skip to content

Commit b9c5535

Browse files
authored
publicize client's elg (AsyncHttpClient#24)
1 parent 92d4e9c commit b9c5535

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

Sources/NIOHTTPClient/SwiftNIOHTTP.swift

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,18 @@ public enum EventLoopGroupProvider {
2424
}
2525

2626
public class HTTPClient {
27+
public let eventLoopGroup: EventLoopGroup
2728
let eventLoopGroupProvider: EventLoopGroupProvider
28-
let group: EventLoopGroup
2929
let configuration: Configuration
30-
3130
let isShutdown = Atomic<Bool>(value: false)
3231

3332
public init(eventLoopGroupProvider: EventLoopGroupProvider, configuration: Configuration = Configuration()) {
3433
self.eventLoopGroupProvider = eventLoopGroupProvider
3534
switch self.eventLoopGroupProvider {
3635
case .shared(let group):
37-
self.group = group
36+
self.eventLoopGroup = group
3837
case .createNew:
39-
self.group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
38+
self.eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
4039
}
4140
self.configuration = configuration
4241
}
@@ -57,7 +56,7 @@ public class HTTPClient {
5756
return
5857
case .createNew:
5958
if self.isShutdown.compareAndExchange(expected: false, desired: true) {
60-
try self.group.syncShutdownGracefully()
59+
try self.eventLoopGroup.syncShutdownGracefully()
6160
} else {
6261
throw HTTPClientError.alreadyShutdown
6362
}
@@ -69,7 +68,7 @@ public class HTTPClient {
6968
let request = try Request(url: url, method: .GET)
7069
return self.execute(request: request)
7170
} catch {
72-
return self.group.next().makeFailedFuture(error)
71+
return self.eventLoopGroup.next().makeFailedFuture(error)
7372
}
7473
}
7574

@@ -78,7 +77,7 @@ public class HTTPClient {
7877
let request = try HTTPClient.Request(url: url, method: .POST, body: body)
7978
return self.execute(request: request)
8079
} catch {
81-
return self.group.next().makeFailedFuture(error)
80+
return self.eventLoopGroup.next().makeFailedFuture(error)
8281
}
8382
}
8483

@@ -87,7 +86,7 @@ public class HTTPClient {
8786
let request = try HTTPClient.Request(url: url, method: .PATCH, body: body)
8887
return self.execute(request: request)
8988
} catch {
90-
return self.group.next().makeFailedFuture(error)
89+
return self.eventLoopGroup.next().makeFailedFuture(error)
9190
}
9291
}
9392

@@ -96,7 +95,7 @@ public class HTTPClient {
9695
let request = try HTTPClient.Request(url: url, method: .PUT, body: body)
9796
return self.execute(request: request)
9897
} catch {
99-
return self.group.next().makeFailedFuture(error)
98+
return self.eventLoopGroup.next().makeFailedFuture(error)
10099
}
101100
}
102101

@@ -105,7 +104,7 @@ public class HTTPClient {
105104
let request = try Request(url: url, method: .DELETE)
106105
return self.execute(request: request)
107106
} catch {
108-
return self.group.next().makeFailedFuture(error)
107+
return self.eventLoopGroup.next().makeFailedFuture(error)
109108
}
110109
}
111110

@@ -117,7 +116,7 @@ public class HTTPClient {
117116
public func execute<T: HTTPClientResponseDelegate>(request: Request, delegate: T, timeout: Timeout? = nil) -> Task<T.Response> {
118117
let timeout = timeout ?? configuration.timeout
119118

120-
let promise: EventLoopPromise<T.Response> = group.next().makePromise()
119+
let promise: EventLoopPromise<T.Response> = self.eventLoopGroup.next().makePromise()
121120

122121
let redirectHandler: RedirectHandler<T.Response>?
123122
if self.configuration.followRedirects {
@@ -130,7 +129,7 @@ public class HTTPClient {
130129

131130
let task = Task(future: promise.futureResult)
132131

133-
var bootstrap = ClientBootstrap(group: group)
132+
var bootstrap = ClientBootstrap(group: self.eventLoopGroup)
134133
.channelOption(ChannelOptions.socket(SocketOptionLevel(IPPROTO_TCP), TCP_NODELAY), value: 1)
135134
.channelInitializer { channel in
136135
let encoder = HTTPRequestEncoder()

0 commit comments

Comments
 (0)