@@ -24,19 +24,18 @@ public enum EventLoopGroupProvider {
24
24
}
25
25
26
26
public class HTTPClient {
27
+ public let eventLoopGroup : EventLoopGroup
27
28
let eventLoopGroupProvider : EventLoopGroupProvider
28
- let group : EventLoopGroup
29
29
let configuration : Configuration
30
-
31
30
let isShutdown = Atomic < Bool > ( value: false )
32
31
33
32
public init ( eventLoopGroupProvider: EventLoopGroupProvider , configuration: Configuration = Configuration ( ) ) {
34
33
self . eventLoopGroupProvider = eventLoopGroupProvider
35
34
switch self . eventLoopGroupProvider {
36
35
case . shared( let group) :
37
- self . group = group
36
+ self . eventLoopGroup = group
38
37
case . createNew:
39
- self . group = MultiThreadedEventLoopGroup ( numberOfThreads: 1 )
38
+ self . eventLoopGroup = MultiThreadedEventLoopGroup ( numberOfThreads: 1 )
40
39
}
41
40
self . configuration = configuration
42
41
}
@@ -57,7 +56,7 @@ public class HTTPClient {
57
56
return
58
57
case . createNew:
59
58
if self . isShutdown. compareAndExchange ( expected: false , desired: true ) {
60
- try self . group . syncShutdownGracefully ( )
59
+ try self . eventLoopGroup . syncShutdownGracefully ( )
61
60
} else {
62
61
throw HTTPClientError . alreadyShutdown
63
62
}
@@ -69,7 +68,7 @@ public class HTTPClient {
69
68
let request = try Request ( url: url, method: . GET)
70
69
return self . execute ( request: request)
71
70
} catch {
72
- return self . group . next ( ) . makeFailedFuture ( error)
71
+ return self . eventLoopGroup . next ( ) . makeFailedFuture ( error)
73
72
}
74
73
}
75
74
@@ -78,7 +77,7 @@ public class HTTPClient {
78
77
let request = try HTTPClient . Request ( url: url, method: . POST, body: body)
79
78
return self . execute ( request: request)
80
79
} catch {
81
- return self . group . next ( ) . makeFailedFuture ( error)
80
+ return self . eventLoopGroup . next ( ) . makeFailedFuture ( error)
82
81
}
83
82
}
84
83
@@ -87,7 +86,7 @@ public class HTTPClient {
87
86
let request = try HTTPClient . Request ( url: url, method: . PATCH, body: body)
88
87
return self . execute ( request: request)
89
88
} catch {
90
- return self . group . next ( ) . makeFailedFuture ( error)
89
+ return self . eventLoopGroup . next ( ) . makeFailedFuture ( error)
91
90
}
92
91
}
93
92
@@ -96,7 +95,7 @@ public class HTTPClient {
96
95
let request = try HTTPClient . Request ( url: url, method: . PUT, body: body)
97
96
return self . execute ( request: request)
98
97
} catch {
99
- return self . group . next ( ) . makeFailedFuture ( error)
98
+ return self . eventLoopGroup . next ( ) . makeFailedFuture ( error)
100
99
}
101
100
}
102
101
@@ -105,7 +104,7 @@ public class HTTPClient {
105
104
let request = try Request ( url: url, method: . DELETE)
106
105
return self . execute ( request: request)
107
106
} catch {
108
- return self . group . next ( ) . makeFailedFuture ( error)
107
+ return self . eventLoopGroup . next ( ) . makeFailedFuture ( error)
109
108
}
110
109
}
111
110
@@ -117,7 +116,7 @@ public class HTTPClient {
117
116
public func execute< T: HTTPClientResponseDelegate > ( request: Request , delegate: T , timeout: Timeout ? = nil ) -> Task < T . Response > {
118
117
let timeout = timeout ?? configuration. timeout
119
118
120
- let promise : EventLoopPromise < T . Response > = group . next ( ) . makePromise ( )
119
+ let promise : EventLoopPromise < T . Response > = self . eventLoopGroup . next ( ) . makePromise ( )
121
120
122
121
let redirectHandler : RedirectHandler < T . Response > ?
123
122
if self . configuration. followRedirects {
@@ -130,7 +129,7 @@ public class HTTPClient {
130
129
131
130
let task = Task ( future: promise. futureResult)
132
131
133
- var bootstrap = ClientBootstrap ( group: group )
132
+ var bootstrap = ClientBootstrap ( group: self . eventLoopGroup )
134
133
. channelOption ( ChannelOptions . socket ( SocketOptionLevel ( IPPROTO_TCP) , TCP_NODELAY) , value: 1 )
135
134
. channelInitializer { channel in
136
135
let encoder = HTTPRequestEncoder ( )
0 commit comments