NAME

DBIO::Async::Pool - Generic async connection pool for DBIO drivers

VERSION

version 0.900001

SYNOPSIS

my $pool = DBIO::Async::Pool->new(
    storage  => $storage,
    conninfo => { host => 'localhost', dbname => 'myapp' },
    size     => 10,
    on_error => sub { warn $_[0] },
);

my $conn = $pool->acquire->get;   # Future resolving to ready connection
$pool->release($conn);            # return to pool
my $conn = $pool->acquire_txn;    # pinned for transaction

DESCRIPTION

Connection pool for DBIO::Async::Storage. Manages a pool of database connections using the idle-list / waiter-queue / capacity mechanics inherited from DBIO::Storage::PoolBase.

This class supplies two additions over PoolBase:

Drivers that need a different pool implementation can subclass this or provide their own DBIO::Storage::PoolBase subclass.

METHODS

new

my $pool = DBIO::Async::Pool->new(
    storage  => $storage,       # required
    conninfo => $conninfo,      # or conninfo_provider
    size     => 10,
    on_error => sub { warn $_[0] },
);

Like "new" in DBIO::Storage::PoolBase, but requires a storage argument (the DBIO::Async::Storage that owns this pool). The storage reference is weakened to avoid a cycle (storage holds pool, pool holds storage).

acquire

Like "acquire" in DBIO::Storage::PoolBase, but the resolved Future does not complete until the connection is actually ready for queries. This correctly handles drivers where connection construction returns before the async connect finishes (e.g. libpq's PQconnectStart).

Readiness is checked via "_await_conn_ready", which delegates to the Storage's "_await_conn_ready" in DBIO::Async::Storage.

_await_conn_ready

my $future = $pool->_await_conn_ready($conn);

Returns a Future that resolves to $conn once it is ready for queries. Delegates to the Storage's "_await_conn_ready" in DBIO::Async::Storage. If the Storage reference has been lost (DESTROY path), short-circuits to an immediately-done Future.

_create_connection

Delegates to the owning Storage's "_create_pool_connection" in DBIO::Async::Storage. The pool tracks the returned connection -- do not push it onto _connections yourself.

_shutdown_connection

Delegates to the owning Storage's "_shutdown_pool_connection" in DBIO::Async::Storage. If the Storage reference has been lost, returns silently (best-effort on DESTROY).

AUTHOR

DBIO Authors

COPYRIGHT AND LICENSE

Copyright (C) 2026 DBIO Authors

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.