Skip to content

Commit

Permalink
added IO::Async example
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 5, 2012
1 parent 20d78ed commit 64d3565
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions lib/Mojolicious/Guides/Cookbook.pod
Expand Up @@ -167,9 +167,9 @@ your applications home directory, otherwise libraries might not be found.

$ plackup ./script/myapp -s FCGI -l /tmp/myapp.sock

Because C<plackup> uses a weird trick to load your script, L<Mojolicious> is
not always able to detect the applications home directory, if that's the case
you can simply use the C<MOJO_HOME> environment variable. Also note that
Because of the way C<plackup> loads your script, L<Mojolicious> is not always
able to detect the applications home directory, if that's the case you can
simply use the C<MOJO_HOME> environment variable. Also note that
C<app-E<gt>start> needs to be the last Perl statement in the application
script for the same reason.

Expand Down Expand Up @@ -612,7 +612,27 @@ which can be combined to solve some of hardest problems in web development.

Internally the L<Mojo::IOLoop> reactor can use multiple event loop backends,
L<EV> for example will be automatically used if installed. Which in turn
allows L<AnyEvent> to just work.
allows event loops like L<IO::Async> to just work.

use Mojolicious::Lite;
use EV;
use IO::Async::Loop::EV;
use IO::Async::Timer::Absolute;

my $loop = IO::Async::Loop::EV->new;

# Wait 3 seconds before rendering a response
get '/' => sub {
my $self = shift;
$loop->add(IO::Async::Timer::Absolute->new(
time => time + 3,
on_expire => sub { $self->render(text => 'Delayed by 3 seconds!') }
));
};

app->start;

Same for L<AnyEvent>.

use Mojolicious::Lite;
use EV;
Expand Down

0 comments on commit 64d3565

Please sign in to comment.