Skip to content

Commit

Permalink
added another foreign event loop recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 16, 2012
1 parent 8200475 commit 857b5f2
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/Mojolicious/Guides/Cookbook.pod
Expand Up @@ -613,6 +613,21 @@ allows L<AnyEvent> to just work.

app->start;

Who actually controls the event loop backend is not important.

use Mojo::UserAgent;
use EV;
use AnyEvent;

# Let AnyEvent take control
my $cv = AE::cv;
my $ua = Mojo::UserAgent->new;
$ua->get('http://search.twitter.com/search.json?q=perl' => sub {
my ($ua, $tx) = @_;
$cv->send($tx->res->json->{results}->[0]->{text});
});
say $cv->recv;

=head1 USER AGENT

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

0 comments on commit 857b5f2

Please sign in to comment.