Skip to content

Instantly share code, notes, and snippets.

Created August 17, 2011 06:52
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 anonymous/1150975 to your computer and use it in GitHub Desktop.
Save anonymous/1150975 to your computer and use it in GitHub Desktop.
my $ua = Mojo::UserAgent->new;
my $t = Mojo::IOLoop::Trigger->new;
for my $step (1..5) {
for my $thread (1..2) {
say "==> $step - $thread";
$ua->get(
'www.twitter.com',
sub {
say "<== $step - $thread";
}
);
}
}
$ua->start;
Is it possible to automatically wait at the end of each step till all sent requests have finished?
So, instead of:
==> 1 - 1
==> 1 - 2
==> 2 - 1
==> 2 - 2
==> 3 - 1
==> 3 - 2
==> 4 - 1
==> 4 - 2
==> 5 - 1
==> 5 - 2
Non-blocking requests in progress at test_ua.pl line 23
it should display:
==> 1 - 1
==> 1 - 2
<== 1 - 1
<== 1 - 2
==> 2 - 1
==> 2 - 2
<== 2 - 1
<== 2 - 2
.........
Looked through Mojo::IOLoop::Trigger but didn't get how I can use it for my purpose.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment