Skip to content

Commit 01cce0c

Browse files
committed
Add HTTPConnectionPool Connection as a box type
1 parent 8d4e2b1 commit 01cce0c

File tree

1 file changed

+77
-1
lines changed

1 file changed

+77
-1
lines changed

Sources/AsyncHTTPClient/ConnectionPool/HTTPConnectionPool.swift

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,84 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15+
import NIO
16+
1517
enum HTTPConnectionPool {
16-
struct Connection {
18+
struct Connection: Equatable {
1719
typealias ID = Int
20+
21+
private enum Reference {
22+
// case http1_1(HTTP1Connection)
23+
24+
case __testOnly_connection(ID, EventLoop)
25+
}
26+
27+
private let _ref: Reference
28+
29+
// fileprivate static func http1_1(_ conn: HTTP1Connection) -> Self {
30+
// Connection(_ref: .http1_1(conn))
31+
// }
32+
33+
static func __testOnly_connection(id: ID, eventLoop: EventLoop) -> Self {
34+
Connection(_ref: .__testOnly_connection(id, eventLoop))
35+
}
36+
37+
var id: ID {
38+
switch self._ref {
39+
// case .http1_1(let connection):
40+
// return connection.id
41+
case .__testOnly_connection(let id, _):
42+
return id
43+
}
44+
}
45+
46+
var eventLoop: EventLoop {
47+
switch self._ref {
48+
// case .http1_1(let connection):
49+
// return connection.channel.eventLoop
50+
case .__testOnly_connection(_, let eventLoop):
51+
return eventLoop
52+
}
53+
}
54+
55+
@discardableResult
56+
fileprivate func close() -> EventLoopFuture<Void> {
57+
switch self._ref {
58+
// case .http1_1(let connection):
59+
// return connection.close()
60+
61+
case .__testOnly_connection(_, let eventLoop):
62+
return eventLoop.makeSucceededFuture(())
63+
}
64+
}
65+
66+
fileprivate func execute(request: HTTPExecutingRequest) {
67+
switch self._ref {
68+
// case .http1_1(let connection):
69+
// return connection.execute(request: request)
70+
case .__testOnly_connection:
71+
break
72+
}
73+
}
74+
75+
fileprivate func cancel() {
76+
switch self._ref {
77+
// case .http1_1(let connection):
78+
// return connection.cancel()
79+
case .__testOnly_connection:
80+
break
81+
}
82+
}
83+
84+
static func == (lhs: HTTPConnectionPool.Connection, rhs: HTTPConnectionPool.Connection) -> Bool {
85+
switch (lhs._ref, rhs._ref) {
86+
// case (.http1_1(let lhsConn), .http1_1(let rhsConn)):
87+
// return lhsConn === rhsConn
88+
case (.__testOnly_connection(let lhsID, let lhsEventLoop), .__testOnly_connection(let rhsID, let rhsEventLoop)):
89+
return lhsID == rhsID && lhsEventLoop === rhsEventLoop
90+
// default:
91+
// return false
92+
}
93+
}
1894
}
1995
}

0 commit comments

Comments
 (0)