Skip to content

Instantly share code, notes, and snippets.

Created May 1, 2017 23:56
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/dca7cd04b47f769889894aab6ef1dee0 to your computer and use it in GitHub Desktop.
Save anonymous/dca7cd04b47f769889894aab6ef1dee0 to your computer and use it in GitHub Desktop.
The below code runs as expected and prints two return codes:
use Mojo::UserAgent;
use Mojo::IOLoop;
sub get {
my ($delay, $ua) = @_;
my $end = $delay->begin();
$ua->get("http://testhost/" => sub {
my ($ua, $tx) = @_;
$end->();
print $tx->result->code . "\n";
});
}
my $delay = Mojo::IOLoop->delay;
my $ua = Mojo::UserAgent->new->connect_timeout(0.2)->request_timeout(5);
get($delay, $ua);
get($delay, $ua);
$delay->wait();
The below code doesn't run any requests and does not print anything:
use Mojo::UserAgent;
use Mojo::IOLoop;
sub get {
my ($delay) = @_;
my $ua = Mojo::UserAgent->new->connect_timeout(0.2)->request_timeout(5);
my $end = $delay->begin();
$ua->get("http://testhost/" => sub {
my ($ua, $tx) = @_;
$end->();
print $tx->result->code . "\n";
});
}
my $delay = Mojo::IOLoop->delay;
get($delay);
get($delay);
$delay->wait();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment