xtpu2 has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to make use of the Postgres Listen/Notify feature in my AnyEvent-based program. I tried looking for a ready solution and found AnyEvent::Pg on CPAN, but I've not been able to get the module to work (and the developer does mention that it is in very early development). So I was trying to figure out the best way to set this up with the tools I have.
Listen/Notify is supported by DBD:Pg, so the solution I came up with is to poll $dbh to see if a notification has been received, like so (posting only the relevant code):
my $w = AnyEvent->timer ( after => 0, interval => 2, cb => sub { if (my $notify = $dbh->pg_notifies){ # Do something } } );
This works. However, I'm not sure this is the best way to do it because I'm just not that familiar with event-based programming. I would really appreciate alternate solutions / thoughts from more knowledgeable people...
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: AnyEvent and Postgres Listen/Notify
by salva (Canon) on Apr 14, 2014 at 07:06 UTC | |
Re: AnyEvent and Postgres Listen/Notify
by nikosv (Deacon) on Apr 14, 2014 at 06:57 UTC |