Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bluet/1263807 to your computer and use it in GitHub Desktop.
Save bluet/1263807 to your computer and use it in GitHub Desktop.
# 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 );
}
);
# 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