@@ -19,7 +19,9 @@ import NIOHTTP1
19
19
import NIOTLS
20
20
21
21
/// A connection pool that manages and creates new connections to hosts respecting the specified preferences
22
- class ConnectionPool {
22
+ ///
23
+ /// - Note: All `internal` methods of this class are thread safe
24
+ final class ConnectionPool {
23
25
/// The configuration used to bootstrap new HTTP connections
24
26
private let configuration : HTTPClient . Configuration
25
27
@@ -44,7 +46,7 @@ class ConnectionPool {
44
46
/// This is part of optimization used by the `.execute(...)` method when
45
47
/// a request has its `EventLoopPreference` property set to `.indifferent`.
46
48
/// Having a default `EventLoop` shared by the *channel* and the *delegate* avoids
47
- /// loss of performance due to `EventLoop` hoping
49
+ /// loss of performance due to `EventLoop` hopping
48
50
func associatedEventLoop( for key: Key ) -> EventLoop ? {
49
51
return self . connectionProvidersLock. withLock {
50
52
self . connectionProviders [ key] ? . eventLoop
@@ -199,7 +201,7 @@ class ConnectionPool {
199
201
}
200
202
}
201
203
202
- /// A connection provider of `HTTP/1.1` connections to a given `Key` (host, scheme, port)
204
+ /// A connection provider of `HTTP/1.1` connections with a given `Key` (host, scheme, port)
203
205
///
204
206
/// On top of enabling connection reuse this provider it also facilitates the creation
205
207
/// of concurrent requests as it has built-in politness regarding the maximum number
@@ -453,7 +455,7 @@ class ConnectionPool {
453
455
self . leased += 1
454
456
let ( channelEL, requiresSpecifiedEL) = self . resolvePreference ( preference)
455
457
456
- if let connection = availableConnections. swapRemove ( where: { $0. channel. eventLoop === channelEL } ) {
458
+ if let connection = availableConnections. swapWithFirstAndRemove ( where: { $0. channel. eventLoop === channelEL } ) {
457
459
connection. isLeased = true
458
460
return . leaseConnection( connection)
459
461
} else {
@@ -514,7 +516,7 @@ class ConnectionPool {
514
516
return . makeConnectionAndComplete( el, firstWaiter. promise)
515
517
}
516
518
} else {
517
- self . availableConnections. swapRemove ( where: { $0 === connection } )
519
+ self . availableConnections. swapWithFirstAndRemove ( where: { $0 === connection } )
518
520
}
519
521
520
522
if self . providerMustClose ( ) {
0 commit comments