Vapor's DatabaseKit package contains a connection pool class for managing database connections. I think it could be useful to make that class more generic and move it here. That would allow for other connections, like HTTP client connections, to easily take advantage of pooling.
Here's an idea of what this might entail:
public protocol ConnectionPoolItem {
var isClosed: Bool { get }
}
public protocol ConnectionPoolSource {
associatedtype Connection: ConnectionPoolItem
var eventLoop: EventLoop { get }
func makeConnection() -> EventLoopFuture<Connection>
}
public struct ConnectionPoolConfig {
var maxConnections: Int
}
public final class ConnectionPool<Source> where Source: ConnectionPoolSource {
init(config: ConnectionPoolConfig, source: Source) { ... }
func requestConnection() -> EventLoopFuture<Source.Connection> { ... }
func releaseConnection(_: Source.Connection)
}
extension ConnectionPool {
func withConnection(_: (Source.Connection) -> EventLoopFuture<Void>) -> EventLoopFuture<Void> { ... }
}
Vapor's DatabaseKit package contains a connection pool class for managing database connections. I think it could be useful to make that class more generic and move it here. That would allow for other connections, like HTTP client connections, to easily take advantage of pooling.
Here's an idea of what this might entail: