AnyEvent-Pg

 view release on metacpan or  search on metacpan

examples/listen.pl  view on Meta::CPAN

use AE;
use AnyEvent::Pg::Pool;

$Pg::PQ::debug = -1;
$AnyEvent::Pg::debug = -1;

my $cv = AE::cv();

my $db = AnyEvent::Pg::Pool->new("dbname=pgpqtest");
my $w = $db->listen('foo',
                    on_listener_started => sub { say "started!!!" },
                    on_notify           => sub { say "foo!" });

warn "waiting for notifications!\n";

$cv->recv();

lib/AnyEvent/Pg.pm  view on Meta::CPAN

            $debug and $debug & 1 and $self->_debug("error");
            $self->_on_connect_error;
            return;
        }
        $r = PGRES_POLLING_WRITING;
    }

    $debug and $debug & 1 and $self->_debug("wants to: $r");
    if    ($r == PGRES_POLLING_READING) {
        $rw = $self->{read_watcher} // AE::io $fd, 0, weak_method_callback_cached($self, '_connectPoll');
        # say "fd: $fd, read_watcher: $rw";
    }
    elsif ($r == PGRES_POLLING_WRITING) {
        $ww = $self->{write_watcher} // AE::io $fd, 1, weak_method_callback_cached($self, '_connectPoll');
        # say "fd: $fd, write_watcher: $ww";
    }
    elsif ($r == PGRES_POLLING_FAILED) {
        $goto = '_on_connect_error';
    }
    elsif ($r == PGRES_POLLING_OK or
           $r == PGRES_POLLING_ACTIVE) {
        $goto = '_on_connect';
    }
    $self->{read_watcher} = $rw;
    $self->{write_watcher} = $ww;



( run in 0.863 second using v1.01-cache-2.11-cpan-483215c6ad5 )