Created
October 5, 2011 06:50
-
-
Save bluet/1263807 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 hidden or 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
# AEcv recurse blocking in Mojolicious Helpers with multiple MojoXRedis | |
# 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 ); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment