EV-Pg
view release on metacpan or search on metacpan
eg/notify.pl view on Meta::CPAN
#!/usr/bin/env perl
use strict;
use warnings;
use EV;
use EV::Pg;
my $conninfo = shift || $ENV{TEST_PG_CONNINFO} || 'dbname=postgres';
my $pg; $pg = EV::Pg->new(
conninfo => $conninfo,
keep_alive => 1,
on_error => sub { die "connection error: $_[0]\n" },
on_notify => sub {
my ($channel, $payload, $pid) = @_;
print "notification on '$channel': $payload (from pid $pid)\n";
EV::break;
},
on_connect => sub {
$pg->query("listen my_channel", sub {
my (undef, $err) = @_;
die $err if $err;
print "listening on my_channel, sending test notification...\n";
$pg->query("notify my_channel, 'hello from EV::Pg'", sub {
my (undef, $err) = @_;
die $err if $err;
});
});
},
);
EV::run;
( run in 1.935 second using v1.01-cache-2.11-cpan-5837b0d9d2c )