Skip to content

Commit

Permalink
better description for begin method
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Dec 24, 2014
1 parent 398f499 commit c9bf5dd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,5 +1,5 @@

5.71 2014-12-20
5.71 2014-12-25
- Updated jQuery to version 2.1.3.

5.70 2014-12-18
Expand Down
14 changes: 9 additions & 5 deletions lib/Mojo/IOLoop/Delay.pm
Expand Up @@ -181,11 +181,10 @@ implements the following new ones.
my $cb = $delay->begin($offset);
my $cb = $delay->begin($offset, $len);
Increment active event counter, the returned callback can be used to decrement
the active event counter again. Arguments passed to the callback are spliced
and queued in the right order for the next step or L</"finish"> event and
L</"wait"> method, the argument offset defaults to C<1> with no default
length.
Indicate an active event by incrementing the active event counter, the
returned callback needs to be called when the event has completed, to
decrement the active event counter again. When all callbacks have been called
and the active event counter reached zero, L</"steps"> will continue.
# Capture all arguments except for the first one (invocant)
my $delay = Mojo::IOLoop->delay(sub {
Expand All @@ -195,6 +194,11 @@ length.
Mojo::IOLoop->client({port => 3000} => $delay->begin);
$delay->wait;
Arguments passed to the returned callback are spliced with the given offset
and length, defaulting to an offset of C<1> with no default length. The
arguments are then combined in the same order C</"begin"> was called, and
passed together to the next step or L</"finish"> event.
# Capture all arguments
my $delay = Mojo::IOLoop->delay(sub {
my ($delay, $loop, $err, $stream) = @_;
Expand Down
2 changes: 2 additions & 0 deletions lib/Mojolicious/Guides/Cookbook.pod
Expand Up @@ -411,6 +411,8 @@ latency backend web services.
</body>
</html>

=head2 Synchronizing events

Multiple events such as concurrent requests can be easily synchronized with
L<Mojolicious::Plugin::DefaultHelpers/"delay">, which can help you avoid deep
nested closures and memory leaks that often result from continuation-passing
Expand Down

0 comments on commit c9bf5dd

Please sign in to comment.