-
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
ConnectionRequestProtocol
, ConnectionPoolError
and `Connectio…
…nPoolConfiguration` (#421)
- Loading branch information
1 parent
5e75c9e
commit a57baa7
Showing
3 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
public struct ConnectionPoolError: Error, Hashable { | ||
enum Base: Error, Hashable { | ||
case requestCancelled | ||
case poolShutdown | ||
} | ||
|
||
private let base: Base | ||
|
||
init(_ base: Base) { self.base = base } | ||
|
||
/// The connection requests got cancelled | ||
public static let requestCancelled = ConnectionPoolError(.requestCancelled) | ||
/// The connection requests can't be fulfilled as the pool has already been shutdown | ||
public static let poolShutdown = ConnectionPoolError(.poolShutdown) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
public struct ConnectionRequest<Connection: PooledConnection>: ConnectionRequestProtocol { | ||
public typealias ID = Int | ||
|
||
public var id: ID | ||
|
||
private var continuation: CheckedContinuation<Connection, ConnectionPoolError> | ||
|
||
init( | ||
id: Int, | ||
continuation: CheckedContinuation<Connection, ConnectionPoolError> | ||
) { | ||
self.id = id | ||
self.continuation = continuation | ||
} | ||
|
||
public func complete(with result: Result<Connection, ConnectionPoolError>) { | ||
self.continuation.resume(with: result) | ||
} | ||
} |