Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save und3f/1263836 to your computer and use it in GitHub Desktop.
Save und3f/1263836 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 );
}
);
# 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 );
}
);
# 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