Skip to content

Commit

Permalink
added another event loop embedding recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 17, 2012
1 parent eb23659 commit 573816f
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lib/Mojolicious/Guides/Cookbook.pod
Expand Up @@ -251,7 +251,7 @@ into alien environments like foreign event loops.
$self->render(text => 'Hello World!');
};

# Connect application with custom daemon and start accepting connections
# Connect application with web server and start accepting connections
my $daemon =
Mojo::Server::Daemon->new(app => app, listen => ['http://*:8080']);
$daemon->start;
Expand Down Expand Up @@ -619,7 +619,7 @@ Who actually controls the event loop backend is not important.
use EV;
use AnyEvent;

# Let AnyEvent take control
# Search Twitter for "perl"
my $cv = AE::cv;
my $ua = Mojo::UserAgent->new;
$ua->get('http://search.twitter.com/search.json?q=perl' => sub {
Expand All @@ -628,6 +628,22 @@ Who actually controls the event loop backend is not important.
});
say $cv->recv;

You could for example just embed the built-in web server into an L<AnyEvent>
application.

use Mojolicious::Lite;
use Mojo::Server::Daemon;
use EV;
use AnyEvent;

get '/' => {text => 'Hello World!'};

# Start web server and let AnyEvent take control
my $daemon =
Mojo::Server::Daemon->new(app => app, listen => ['http://*:8080']);
$daemon->start;
AE::cv->recv;

=head1 USER AGENT

When we say L<Mojolicious> is a web framework we actually mean it.
Expand Down

0 comments on commit 573816f

Please sign in to comment.