Ok my mistake was to declare $ua and $delay inside the recurring callback 
instead of the startup sub.

Now it's working ok.

sub startup {
>   my $self = shift;
>   # Router
>   my $r = $self->routes;
>   $r->get('/')->to('example#welcome');
>     
>   my $ua = Mojo::UserAgent->new;
>   my $delay;
>   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)
>     $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;
>     print("leave timer\n");
>   });
> }

 
I still think it could be a good example to add in doc in the wiki.

Thanks 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