Instance Method
withConnection(logger:on:_:)
Fetches a pooled connection for the lifetime of the closure.
func withConnection<Result>(logger: Logger? = nil, on eventLoop: (any EventLoop)? = nil, _ closure: @escaping (Source.Connection) -> EventLoopFuture<Result>) -> EventLoopFuture<Result>
Parameters
loggerFor trace and debug logs.
eventLoopPreferred event loop for the new connection.
closureCallback that accepts the pooled connection.
Return Value
A future containing the result of the closure.
Discussion
The connection is provided to the supplied callback and will be automatically released when the future returned by the callback is completed.
pool.withConnection(...) { conn in
// use the connection
}
See requestConnection(logger:on:) to request a pooled connection without using a callback.