Skip to content

Commit

Permalink
use steps consistently for synchronization of events in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 27, 2014
1 parent 01c7093 commit 7f55448
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/Mojo/IOLoop/Delay.pm
Expand Up @@ -240,11 +240,12 @@ event counter or an error occurs in a callback.
Start L</"ioloop"> and stop it again once an L</"error"> or L</"finish"> event
gets emitted, only works when L</"ioloop"> is not running already.
# Use the "finish" event to synchronize portably
$delay->on(finish => sub {
# Use a single step to synchronize portably
$delay->steps(sub {
my ($delay, @args) = @_;
...
});
Mojo::IOLoop->timer($_ => $delay->begin) for 1 .. 10;
$delay->wait unless $delay->ioloop->is_running;
=head1 SEE ALSO
Expand Down
7 changes: 3 additions & 4 deletions lib/Mojolicious/Guides/Cookbook.pod
Expand Up @@ -1042,16 +1042,15 @@ synchronize multiple non-blocking requests.
$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 an already running event loop.
One or more steps can be used for code that needs to be able to work
standalone as well as inside an already running event loop.

use Mojo::UserAgent;
use Mojo::IOLoop;

# Synchronize non-blocking requests portably
my $ua = Mojo::UserAgent->new;
my $delay = Mojo::IOLoop->delay;
$delay->on(finish => sub {
my $delay = Mojo::IOLoop->delay(sub {
my ($delay, $mojo, $mango) = @_;
...
});
Expand Down

0 comments on commit 7f55448

Please sign in to comment.