Created
October 29, 2010 17:06
-
-
Save jzawodn/653912 to your computer and use it in GitHub Desktop.
AnyEvent Perl BLPOP loop. Has memory leak.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
$|=1; | |
use strict; | |
use lib '/home/jzawodn/code/AnyEvent-Redis/lib'; | |
use AnyEvent::Redis; | |
my $host = 'localhost'; | |
my $port = 6379; | |
my @chan = 'a'..'z'; # which queues/channels to check | |
my $command_timeout = 1; # how long to wait for a response | |
my $done_cv = AnyEvent->condvar; | |
$done_cv->begin; | |
my $redis = AnyEvent::Redis->new(host => $host, port => $port, | |
on_error => sub { warn @_; $done_cv->end; } | |
); | |
sub handler; | |
sub handler { | |
my ($stuff) = @_; | |
if ($stuff) { | |
my ($key, $msg) = @$stuff; | |
print "got $msg via $key\n"; | |
} else { | |
print "blpop timeout\n"; | |
} | |
$redis->blpop(@chan, $command_timeout, sub { handler(@_); }); | |
}; | |
handler(); | |
$done_cv->recv; | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compare with: http://gist.github.com/653910