thanx, I tried Mojo::IOLoop->delay as well. But I did not find a way to queue the request in order to limit the maximum allowed concurrent request spawned. (being polite to the web server). Is queue even the right pattern for that? Sorry I am very new to mojo and do not know the framework well.
On Tuesday, 30 June 2015 15:08:12 UTC+2, Dan Book wrote: > > 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] > <javascript:>> 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] <javascript:>. >> >> To post to this group, send email to [email protected] >> <javascript:>. >> >> 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] <javascript:>. >> To post to this group, send email to [email protected] >> <javascript:>. >> 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.
