is_running isn't what takes 20 seconds, Mojo::IOLoop->start blocks until
the event loop is stopped/has nothing more to do. So it waits for your
requests to complete. Delays are an easier option to synchronize
non-blocking requests, see
https://metacpan.org/pod/Mojolicious::Guides::Cookbook#Concurrent-blocking-requests

-Dan

On Tue, Jun 30, 2015 at 3:30 AM, Ben van Staveren <[email protected]>
wrote:

>  Hmm, like this maybe:
>
> use strict;
> use warnings;
> use Mojo::UserAgent;
> use Mojo::IOLoop;
>
> my $ua = Mojo::UserAgent->new;
>
> my $delay = Mojo::IOLoop->delay(sub {
>   my $delay = shift;
>   exit(0);
> });
>
> foreach my $url ('http://www.google.com/', 'http://www.google.com/') {
>   my $end = $delay->begin(0);
>   $ua->get($url => sub {
>     say $tx->res->code . ' ' . scalar(localtime());
>     $end->();
>   });
> }
>
> Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
>
>
>
> On 06/30/2015 02:22 PM, Mario Gee wrote:
>
> Hi
>
>  I am trying to make concurrent requests like this:
>
>   use 5.016;
>  use Mojo::UserAgent;
>
>   my $ua = Mojo::UserAgent->new;
>  say "starting " . scalar localtime();
>
>   my $tx = Mojo::Transaction::HTTP->new;
>  $tx->req->method('GET');
>  $tx->req->url->parse('http://www.google.com/');
>  $ua->start($tx => \&mojo_callback);
>
>   $tx = Mojo::Transaction::HTTP->new;
>  $tx->req->method('GET');
>  $tx->req->url->parse('http://www.google.com/');
>  $ua->start($tx => \&mojo_callback);
>
>   sub mojo_callback{
>    my ($ua, $tx) = @_;
>    say $tx->res->code . " " .  scalar localtime() ;
>  }
>
>   Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
>
>   say "after is_running " . scalar localtime();
>
>
>
>  But is_running is taking up to 20 seconds until finish.
>
>  How can I enqueue 2 concurrent requests and after both ended immediatly
> continue?
>
>  cheers
>
>
>
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Mojolicious" group.
>
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
>
> To post to this group, send email to [email protected].
>
> Visit this group at http://groups.google.com/group/mojolicious.
>
> For more options, visit https://groups.google.com/d/optout.
>
>
>
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Mojolicious" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to