Skip to content

Instantly share code, notes, and snippets.

@nicomen
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicomen/27d230c124585532276f to your computer and use it in GitHub Desktop.
Save nicomen/27d230c124585532276f to your computer and use it in GitHub Desktop.
# Synchronize non-blocking requests
my $ua = Mojo::UserAgent->new;
sub list {
my ($self) = @_;
my $section = $self->stash('section');
my $news = [];
my $delay = Mojo::IOLoop->delay(sub {
my ($delay, @results) = @_;
warn Mojo::Util::dumper([@results]);
do { warn $_->res->error->{message} if $_->res->error } for @results;
});
map { $ua->get( $_ => $delay->begin() ) } @{ $sections->{$section}->{feeds} };
$delay->wait;
$self->render(
template => 'newslists/index',
current_section => $section,
title => "Nyhetslister / $section",
sections => $sections,
news => $news,
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment