Forked from bluet/AE::cv recurse blocking in Mojolicious Helpers with multiple MojoX::Redis
Created
October 5, 2011 07:09
-
-
Save und3f/1263836 to your computer and use it in GitHub Desktop.
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
# Add "get_board_info" helper | |
$app->helper( | |
get_board_info => sub { | |
my $c = shift; | |
my $data_id = shift; | |
my @keys = @_; | |
my $aecv = AE::cv; | |
my %data; | |
$aecv->begin (sub { shift->send(\%data) }); # Outer CV | |
for my $key (@keys) { | |
$aecv->begin; # Job CV | |
Conifer->redis->get("board:$data_id:$key" => sub { | |
my ($redis, $res) = @_; | |
$data{$key} = $res->[0]; | |
$aecv->end; | |
}); | |
} | |
$aecv->end; # Outer CV | |
$aecv->recv; # non-blocking wait for all jobs | |
return ( \%data ); | |
} | |
); |
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
# Add "get_board_info" helper | |
$app->helper( | |
get_board_info => sub { | |
my $c = shift; | |
my $data_id = shift; | |
my @keys = @_; | |
my $aecv = AE::cv; | |
my %data; | |
$aecv->begin (sub { shift->send(\%data) }); # Outer CV | |
for my $key (@keys) { | |
$aecv->begin; # Job CV | |
Conifer->redis->get("board:$data_id:$key" => sub { | |
my ($redis, $res) = @_; | |
$data{$key} = $res->[0]; | |
$aecv->end; | |
}); | |
} | |
$aecv->end; # Outer CV | |
$aecv->recv; # non-blocking wait for all jobs | |
return ( \%data ); | |
} | |
); |
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
# Add "get_board_info" helper | |
$app->helper( | |
get_board_info => sub { | |
my $c = shift; | |
my $data_id = shift; | |
my @keys = @_; | |
my $redis = Mojox::Redis->new(ioloop => Mojo::IOLoop->new); | |
my %data; | |
my $counter = scalar @keys; | |
for my $key (@keys) { | |
$redis->get("board:$data_id:$key" => sub { | |
my ($redis, $res) = @_; | |
$data{$key} = $res->[0]; | |
$redis->stop if --$count == 0; | |
}); | |
}; | |
$redis->start; | |
return ( \%data ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment