Skip to content

Commit eb5cd0a

Browse files
committed
use index(_:offsetBy:) to convert from offset to index
1 parent e69f32d commit eb5cd0a

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Sources/AsyncHTTPClient/ConnectionPool/State Machine/HTTPConnectionPool+HTTP2Connections.swift

+7-7
Original file line numberDiff line numberDiff line change
@@ -432,18 +432,18 @@ extension HTTPConnectionPool {
432432
return self.leaseStreams(at: index, count: 1)
433433
}
434434

435-
/// tries to find an available connection on the prefered `eventLoop`. If it can't find one with the given `eventLoop`, it returns the first available connection
435+
/// tries to find an available connection on the preferred `eventLoop`. If it can't find one with the given `eventLoop`, it returns the first available connection
436436
private func findAvailableConnection(onPreferred eventLoop: EventLoop) -> Int? {
437-
var availableConnection: Int?
438-
for (index, connection) in self.connections.enumerated() {
437+
var availableConnectionIndex: Int?
438+
for (offset, connection) in self.connections.enumerated() {
439439
guard connection.isAvailable else { continue }
440440
if connection.eventLoop === eventLoop {
441-
return index
442-
} else if availableConnection == nil {
443-
availableConnection = index
441+
return self.connections.index(self.connections.startIndex, offsetBy: offset)
442+
} else if availableConnectionIndex == nil {
443+
availableConnectionIndex = self.connections.index(self.connections.startIndex, offsetBy: offset)
444444
}
445445
}
446-
return availableConnection
446+
return availableConnectionIndex
447447
}
448448

449449
mutating func leaseStream(onRequired eventLoop: EventLoop) -> Connection? {

0 commit comments

Comments
 (0)