NAME
MongoDB::Async::Pool - Pool of connections
SYNOPSIS
You can't use one connection in several coro's because one coro can try send query while other coro waiting for response from already running query. Creating new connection for every coroutine might be slow, so this module caches connections for you.
my $pool = MongoDB::Async::Pool->new({}, { timeout => 0, max_conns => 50 });
async {
my $big_data = $pool->get->testdb->testcoll->find({ giveme => 'large dataset'})->data;
};
async {
my $big_data = $pool->get->testdb->testcoll->find({ giveme => 'another large dataset'})->data;
};
#it's good idea to cache connection in variable if you going to use it several times
async {
my $connection = $pool->get;
# do queries
};
EV::run;
METHODS
new({ MongoDB::Async::MongoClient args }, { MongoDB::Async::Pool attrs });
Creates pool of MongoDB::Async::Connection objects
$pool->get;
Returns MongoDB::Async::MongoClient object from pool or creates new connection if pool is empty. Might block current coro until some coro return connection if pool is empty and "max_conns" connections currently in use. You needn't think about returning object to pool, it`ll be returned on DESTROY
ATTRIBUTES:
->max_conns , ->max_conns(new value)
Max connection count. ->get will block current coroutine when max_conns reached. Not recomended to change it in runtime. Default: 0 - no limit