Skip to content

Commit 0856060

Browse files
committed
Code review
1 parent c760393 commit 0856060

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

Diff for: Sources/AsyncHTTPClient/ConnectionPool/HTTPConnectionPool.swift

+34-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import NIO
1616

1717
enum HTTPConnectionPool {
18-
struct Connection: Equatable {
18+
struct Connection: Hashable {
1919
typealias ID = Int
2020

2121
private enum Reference {
@@ -91,5 +91,38 @@ enum HTTPConnectionPool {
9191
// return false
9292
}
9393
}
94+
95+
func hash(into hasher: inout Hasher) {
96+
switch self._ref {
97+
case .__testOnly_connection(let id, let eventLoop):
98+
hasher.combine(id)
99+
hasher.combine(eventLoop.id)
100+
}
101+
}
102+
}
103+
}
104+
105+
struct EventLoopID: Hashable {
106+
private var id: Identifier
107+
108+
private enum Identifier: Hashable {
109+
case objectIdentifier(ObjectIdentifier)
110+
case __testOnly_fakeID(Int)
94111
}
112+
113+
init(_ eventLoop: EventLoop) {
114+
self.init(.objectIdentifier(ObjectIdentifier(eventLoop)))
115+
}
116+
117+
private init(_ id: Identifier) {
118+
self.id = id
119+
}
120+
121+
static func __testOnly_fakeID(_ id: Int) -> EventLoopID {
122+
return EventLoopID(.__testOnly_fakeID(id))
123+
}
124+
}
125+
126+
extension EventLoop {
127+
var id: EventLoopID { EventLoopID(self) }
95128
}

0 commit comments

Comments
 (0)