xeronuro
11/18/2012 - 5:07 AM

An example showing how to use a Mojo::IOLoop.

An example showing how to use a Mojo::IOLoop.

#!/usr/bin/env perl
use Mojolicious::Lite;
use Coro;
use Mojo::IOLoop;

Mojo::IOLoop->recurring(0 => sub {cede});

hook around_dispatch => sub {
  my $next = shift;
  async { $next->() };
};

get '/' => sub {
  my $self = shift;
  my $ua   = Mojo::UserAgent->new;

  # Comment this line out to see the performance difference
  $ua->ioloop->recurring(0 => sub {cede});

  $self->render(
    text => $ua->get('mojolicio.us')->res->dom->html->head->title->text);
};

app->start;