NAME

DBIx::Connector::Pool - A pool of DBIx::Connector or its subclasses for asynchronous environment

SYNOPSIS

use Coro;
use AnyEvent;
use Coro::AnyEvent;
use DBIx::Connector::Pool;

my $pool = DBIx::Connector::Pool->new(
  initial    => 1,
  keep_alive => 1,
  max_size   => 5,
  tid_func   => sub {"$Coro::current" =~ /(0x[0-9a-f]+)/i; hex $1},
  wait_func => sub        {Coro::AnyEvent::sleep 0.05},
  attrs     => {RootClass => 'DBIx::PgCoroAnyEvent'}
);

async {
  my $connector = $pool->get_connector;
  $connector->run(
    sub {
      my $sth = $_->prepare(q{select isbn, title, rating from books});
      $sth->execute;
      my ($isbn, $title, $rating) = $sth->fetchrow_array;
      # ... 
    }
  );
};

Description

DBI is great and DBIx::Connector is a nice interface with good features to it. But when it comes to work in some asynchronous environment like AnyEvent you have to use something another with callbacks if you don't want to block your event loop completely waiting for data from DB. This module (together with DBIx::PgCoroAnyEvent for PostgreSQL or some another alike) was developed to overcome this inconvenience. You can write your "normal" DBI code without blocking your event loop.

This module requires some threading model and I know about only one really working Coro.

Methods

SEE ALSO

BUGS

Currently this module tested only for PostgreSQL + Coro + AnyEvent.

AUTHOR

This module was written and is maintained by Anton Petrusevich.

Copyright and License

Copyright (c) 2016 Anton Petrusevich. Some Rights Reserved.

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