Skip to content

Commit 26df213

Browse files
committed
NIT: Name and doc fixes
1 parent 008d436 commit 26df213

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

Sources/AsyncHTTPClient/ConnectionPool.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ import NIOHTTP1
1919
import NIOTLS
2020

2121
/// 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 {
2325
/// The configuration used to bootstrap new HTTP connections
2426
private let configuration: HTTPClient.Configuration
2527

@@ -44,7 +46,7 @@ class ConnectionPool {
4446
/// This is part of optimization used by the `.execute(...)` method when
4547
/// a request has its `EventLoopPreference` property set to `.indifferent`.
4648
/// 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
4850
func associatedEventLoop(for key: Key) -> EventLoop? {
4951
return self.connectionProvidersLock.withLock {
5052
self.connectionProviders[key]?.eventLoop
@@ -199,7 +201,7 @@ class ConnectionPool {
199201
}
200202
}
201203

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)
203205
///
204206
/// On top of enabling connection reuse this provider it also facilitates the creation
205207
/// of concurrent requests as it has built-in politness regarding the maximum number
@@ -453,7 +455,7 @@ class ConnectionPool {
453455
self.leased += 1
454456
let (channelEL, requiresSpecifiedEL) = self.resolvePreference(preference)
455457

456-
if let connection = availableConnections.swapRemove(where: { $0.channel.eventLoop === channelEL }) {
458+
if let connection = availableConnections.swapWithFirstAndRemove(where: { $0.channel.eventLoop === channelEL }) {
457459
connection.isLeased = true
458460
return .leaseConnection(connection)
459461
} else {
@@ -514,7 +516,7 @@ class ConnectionPool {
514516
return .makeConnectionAndComplete(el, firstWaiter.promise)
515517
}
516518
} else {
517-
self.availableConnections.swapRemove(where: { $0 === connection })
519+
self.availableConnections.swapWithFirstAndRemove(where: { $0 === connection })
518520
}
519521

520522
if self.providerMustClose() {

Sources/AsyncHTTPClient/Utils.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ extension ClientBootstrap {
6868

6969
extension CircularBuffer {
7070
@discardableResult
71-
mutating func swapRemove(at index: Index) -> Element? {
71+
mutating func swapWithFirstAndRemove(at index: Index) -> Element? {
7272
precondition(index >= self.startIndex && index < self.endIndex)
7373
if !self.isEmpty {
7474
self.swapAt(self.startIndex, index)
@@ -79,9 +79,9 @@ extension CircularBuffer {
7979
}
8080

8181
@discardableResult
82-
mutating func swapRemove(where predicate: (Element) throws -> Bool) rethrows -> Element? {
82+
mutating func swapWithFirstAndRemove(where predicate: (Element) throws -> Bool) rethrows -> Element? {
8383
if let existingIndex = try self.firstIndex(where: predicate) {
84-
return self.swapRemove(at: existingIndex)
84+
return self.swapWithFirstAndRemove(at: existingIndex)
8585
} else {
8686
return nil
8787
}

0 commit comments

Comments
 (0)