Class
EventLoopConnectionPool
Holds a collection of active connections that can be requested and later released back into the pool.
final class EventLoopConnectionPool<Source> where Source : ConnectionPoolSource
Overview
Connection pools are used to offset the overhead of creating new connections. Newly opened connections are returned back to the pool and can be re-used until they close.
New connections are created as needed until the maximum configured connection limit is reached. After the maximum is reached, no new connections will be created unless existing connections are closed.
let pool = EventLoopConnectionPool(...)
pool.withConnection(...) { conn in
// use conn
}
Topics
Initializers
convenience init(source: Source, maxConnections: Int, requestTimeout: TimeAmount, logger: Logger, on: any EventLoop)Creates a newEventLoopConnectionPool.init(source: Source, maxConnections: Int, requestTimeout: TimeAmount, pruneInterval: TimeAmount?, maxIdleTimeBeforePruning: TimeAmount, logger: Logger, on: any EventLoop)Creates a newEventLoopConnectionPool.
Instance Properties
let eventLoop: any EventLoopThis pool’s event loop.let logger: LoggerFor lifecycle logs.let source: SourceConnection source.
Instance Methods
func close() -> EventLoopFuture<Void>Closes the connection pool.func releaseConnection(Source.Connection)Releases a connection back to the pool. Use withrequestConnection().func releaseConnection(Source.Connection, logger: Logger)Releases a connection back to the pool. Use withrequestConnection(logger:).func requestConnection() -> EventLoopFuture<Source.Connection>Requests a pooled connection.func requestConnection(logger: Logger) -> EventLoopFuture<Source.Connection>Requests a pooled connection.func withConnection<Result>((Source.Connection) -> EventLoopFuture<Result>) -> EventLoopFuture<Result>Fetches a pooled connection for the lifetime of the closure.func withConnection<Result>(logger: Logger, (Source.Connection) -> EventLoopFuture<Result>) -> EventLoopFuture<Result>Fetches a pooled connection for the lifetime of the closure.
See Also
Legacy connection pools
class EventLoopGroupConnectionPoolHolds a collection of connection pools for eachEventLoopon anEventLoopGroup.protocol ConnectionPoolSourceSource of new connections forEventLoopGroupConnectionPool.protocol ConnectionPoolItemItem managed by a connection pool.enum ConnectionPoolErrorErrors thrown byEventLoopGroupConnectionPoolandEventLoopConnectionPoolregarding state.enum ConnectionPoolTimeoutErrorErrors thrown byEventLoopGroupConnectionPoolandEventLoopConnectionPoolregarding timeouts.