Skip to content

Instance Method

withConnection(logger:_:)

Fetches a pooled connection for the lifetime of the closure.
func withConnection<Result>(logger: Logger, _ closure: @escaping (Source.Connection) -> EventLoopFuture<Result>) -> EventLoopFuture<Result>

Parameters

logger

For trace and debug logs.

closure

Callback 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:) to request a pooled connection without using a callback.