MCPcopy
hub / github.com/jackc/pgx / AcquireFunc

Method AcquireFunc

pgxpool/pool.go:671–679  ·  view source on GitHub ↗

AcquireFunc acquires a [Conn] and calls f with that [Conn]. ctx will only affect the [Pool.Acquire]. It has no effect on the call of f. The return value is either an error acquiring the [Conn] or the return value of f. The [Conn] is automatically released after the call of f.

(ctx context.Context, f func(*Conn) error)

Source from the content-addressed store, hash-verified

669// call of f. The return value is either an error acquiring the [Conn] or the return value of f. The [Conn] is
670// automatically released after the call of f.
671func (p *Pool) AcquireFunc(ctx context.Context, f func(*Conn) error) error {
672 conn, err := p.Acquire(ctx)
673 if err != nil {
674 return err
675 }
676 defer conn.Release()
677
678 return f(conn)
679}
680
681// AcquireAllIdle atomically acquires all currently idle connections. Its intended use is for health check and
682// keep-alive functionality. It does not update pool statistics.

Callers 2

TestPoolAcquireFuncFunction · 0.80

Calls 2

AcquireMethod · 0.95
ReleaseMethod · 0.80

Tested by 2

TestPoolAcquireFuncFunction · 0.64