Class
EventLoopGroupConnectionPool
Holds a collection of connection pools for each
EventLoop on an EventLoopGroup.final class EventLoopGroupConnectionPool<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 = EventLoopGroupConnectionPool(...)
pool.withConnection { conn in
// use conn
}
Topics
Initializers
convenience init(source: Source, maxConnectionsPerEventLoop: Int, requestTimeout: TimeAmount, logger: Logger, on: any EventLoopGroup)Creates a newEventLoopGroupConnectionPool.init(source: Source, maxConnectionsPerEventLoop: Int, requestTimeout: TimeAmount, pruneInterval: TimeAmount?, maxIdleTimeBeforePruning: TimeAmount, logger: Logger, on: any EventLoopGroup)Creates a newEventLoopGroupConnectionPool.
Instance Properties
let eventLoopGroup: any EventLoopGroupEvent loop source when not specified.let maxConnectionsPerEventLoop: IntLimits the maximum number of connections that can be open at a given time for a single connection pool.let source: SourceCreates new connections when needed. SeeConnectionPoolSource.
Instance Methods
func pool(for: any EventLoop) -> EventLoopConnectionPool<Source>Returns theEventLoopConnectionPoolfor a specific event loop.func releaseConnection(Source.Connection, logger: Logger?)Releases a connection back to the pool. Use withrequestConnection(logger:on:).func requestConnection(logger: Logger?, on: (any EventLoop)?) -> EventLoopFuture<Source.Connection>Requests a pooled connection.func shutdown()Closes the connection pool.func shutdownAsync() async throwsCloses the connection pool.func shutdownGracefully(((any Error)?) -> Void)Closes the connection pool.func syncShutdownGracefully() throwsCloses the connection pool.func withConnection<Result>(logger: Logger?, on: (any EventLoop)?, (Source.Connection) -> EventLoopFuture<Result>) -> EventLoopFuture<Result>Fetches a pooled connection for the lifetime of the closure.
See Also
Legacy connection pools
class EventLoopConnectionPoolHolds a collection of active connections that can be requested and later released back into the pool.protocol ConnectionPoolSourceSource of new connections forEventLoopGroupConnectionPool.protocol ConnectionPoolItemItem managed by a connection pool.enum ConnectionPoolErrorErrors thrown byEventLoopGroupConnectionPoolandEventLoopConnectionPoolregarding state.enum ConnectionPoolTimeoutErrorErrors thrown byEventLoopGroupConnectionPoolandEventLoopConnectionPoolregarding timeouts.