Skip to content

Commit

Permalink
added pass method to Mojo::IOLoop::Delay
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 22, 2014
1 parent 40b0d93 commit a3dacec
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,7 +1,7 @@

4.84 2014-02-22
- Added remaining attribute to Mojo::IOLoop::Delay.
- Added data method to Mojo::IOLoop::Delay.
- Added data and pass methods to Mojo::IOLoop::Delay.

4.83 2014-02-19
- Improved Mojo::JSON to handle encoding errors more gracefully.
Expand Down
12 changes: 12 additions & 0 deletions lib/Mojo/IOLoop/Delay.pm
Expand Up @@ -16,6 +16,8 @@ sub begin {

sub data { shift->Mojo::_dict(data => @_) }

sub pass { $_[0]->begin->(@_) }

sub steps {
my $self = shift->remaining([@_]);
$self->ioloop->timer(0 => $self->begin);
Expand Down Expand Up @@ -185,6 +187,16 @@ Data shared between all L</"steps">.
# Remove value
my $foo = delete $delay->data->{foo};
=head2 pass
$delay->pass(@args);
Increment active event counter and decrement it again right away to pass
values to the next step.
# Longer version
$delay->begin(0)->(@args);
=head2 steps
$delay = $delay->steps(sub {...}, sub {...});
Expand Down
6 changes: 3 additions & 3 deletions t/mojo/delay.t
Expand Up @@ -96,7 +96,7 @@ $delay->steps(
sub { Mojo::IOLoop->timer(0 => shift->begin) },
sub {
$result = 'fail';
shift->begin->();
shift->pass;
},
sub { $result = 'success' },
sub { $result = 'fail' }
Expand All @@ -110,7 +110,7 @@ is $result, 'success', 'right result';
$delay = Mojo::IOLoop::Delay->new;
$delay->on(finish => sub { shift; push @results, [@_] });
$delay->steps(
sub { shift->begin(0)->(23) },
sub { shift->pass(23) },
sub { shift; push @results, [@_] },
sub { push @results, 'fail' }
);
Expand Down Expand Up @@ -163,7 +163,7 @@ $delay = Mojo::IOLoop->delay(
$end2->(4);
$end3->(5, 6);
$end->(1, 2, 3);
$first->begin(0)->(23);
$first->pass(23);
},
sub {
my ($first, @numbers) = @_;
Expand Down

0 comments on commit a3dacec

Please sign in to comment.