Hi, 

In the UserAgent's doc <http://mojolicio.us/perldoc/Mojo/UserAgent>

I read that I can do Non-blocking HTTP requests that does work inside a 
running event loop.

So i thought I could run the example code of the documentation inside the 
callback of a recurring call like this:

use Mojo::Base 'Mojolicious';
> use Data::Dumper;
> use Mojo::IOLoop;
> # This method will run once at server start
> sub startup {
>   my $self = shift;
>   my $timer_id = Mojo::IOLoop->recurring(20 => sub {
>     print("enter timer\n");
>     # Non-blocking parallel requests (should work inside a running event 
> loop according to the doc)
>     my $ua = Mojo::UserAgent->new;
>     my $delay = Mojo::IOLoop->delay(sub {
>       my ($delay, @titles) = @_;
>       print (Dumper(@titles));
>     });
>     for my $url ('mojolicio.us', 'cpan.org') {
>       my $end = $delay->begin(0);
>       $ua->get($url => sub {
>         my ($ua, $tx) = @_;
>         $end->($tx->res->dom->at('title')->text);
>       });
>     }
>     $delay->wait unless Mojo::IOLoop->is_running;
>     sleep(10);
>     print("leave timer\n");
>   });
> }


but it does not work as expected, and I got a "Premature connection close" 
error message for both http requests. I put the sleep(10); to make sure I 
gave enough time for both requests to get through, but that doesn't help.

What I am missing or doing wrong?

Best Regards.

Vincent

-- 
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/groups/opt_out.

Reply via email to