Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
better examples for parallel blocking requests
  • Loading branch information
kraih committed Sep 8, 2013
1 parent f3ad746 commit 7f8eaf1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
2 changes: 2 additions & 0 deletions Changes
@@ -1,4 +1,6 @@

4.35 2013-09-09

4.34 2013-09-08
- Fixed portability bug in SO_REUSEPORT tests.

Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious.pm
Expand Up @@ -41,7 +41,7 @@ has static => sub { Mojolicious::Static->new };
has types => sub { Mojolicious::Types->new };

our $CODENAME = 'Top Hat';
our $VERSION = '4.34';
our $VERSION = '4.35';

sub AUTOLOAD {
my $self = shift;
Expand Down
24 changes: 12 additions & 12 deletions lib/Mojolicious/Guides/Cookbook.pod
Expand Up @@ -979,12 +979,12 @@ can keep many parallel connections active at the same time.

# Parallel non-blocking requests
my $ua = Mojo::UserAgent->new;
$ua->get('http://mojolicio.us' => sub {
my ($ua, $tx) = @_;
$ua->get('http://metacpan.org/search?q=mojo' => sub {
my ($ua, $mojo) = @_;
...
});
$ua->get('http://mojolicio.us/perldoc' => sub {
my ($ua, $tx) = @_;
$ua->get('http://metacpan.org/search?q=mango' => sub {
my ($ua, $mango) = @_;
...
});

Expand All @@ -1001,15 +1001,15 @@ synchronize multiple non-blocking requests.
use Mojo::UserAgent;
use Mojo::IOLoop;

# Synchronize non-blocking requests and capture result
# Synchronize non-blocking requests and capture results
my $ua = Mojo::UserAgent->new;
my $delay = Mojo::IOLoop->delay;
$ua->get('http://mojolicio.us' => $delay->begin);
$ua->get('http://mojolicio.us/perldoc' => $delay->begin);
my ($tx, $tx2) = $delay->wait;
$ua->get('http://metacpan.org/search?q=mojo' => $delay->begin);
$ua->get('http://metacpan.org/search?q=mango' => $delay->begin);
my ($mojo, $mango) = $delay->wait;

The event L<Mojo::IOLoop::Delay/"finish"> can be used for code that needs to
be able to work standalone as well as inside L<Mojolicious> applications.
be able to work standalone as well as inside an already running event loop.

use Mojo::UserAgent;
use Mojo::IOLoop;
Expand All @@ -1018,11 +1018,11 @@ be able to work standalone as well as inside L<Mojolicious> applications.
my $ua = Mojo::UserAgent->new;
my $delay = Mojo::IOLoop->delay;
$delay->on(finish => sub {
my ($delay, $tx, $tx2) = @_;
my ($delay, $mojo, $mango) = @_;
...
});
$ua->get('http://mojolicio.us' => $delay->begin);
$ua->get('http://mojolicio.us/perldoc' => $delay->begin);
$ua->get('http://metacpan.org/search?q=mojo' => $delay->begin);
$ua->get('http://metacpan.org/search?q=mango' => $delay->begin);
$delay->wait unless Mojo::IOLoop->is_running;

=head2 Command line
Expand Down

0 comments on commit 7f8eaf1

Please sign in to comment.