Skip to content

Instantly share code, notes, and snippets.

@jzawodn
Created October 29, 2010 17:05
Show Gist options
  • Save jzawodn/653910 to your computer and use it in GitHub Desktop.
Save jzawodn/653910 to your computer and use it in GitHub Desktop.
AnyEvent Perl GET loop. No memory leak.
#!/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 $key = 'foo';
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) {
print "got $stuff via $key\n";
} else {
print "no data\n";
}
$redis->get($key, sub { handler(@_); });
};
handler();
$done_cv->recv;
exit;
@jzawodn
Copy link
Author

jzawodn commented Oct 29, 2010

@jzawodn
Copy link
Author

jzawodn commented Oct 29, 2010

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment