Skip to content

Commit

Permalink
better timing tests for delays
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 5, 2013
1 parent 3afd358 commit cd04cd8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
14 changes: 8 additions & 6 deletions lib/Mojo/IOLoop/Delay.pm
Expand Up @@ -57,7 +57,7 @@ sub _step {

return 0 if $self->{pending};
if ($self->{counter}) { $self->ioloop->timer(0 => $self->begin) }
else { $self->emit(finish => @args) unless $self->{counter} }
else { $self->emit(finish => @args) }
return 0;
}

Expand Down Expand Up @@ -127,7 +127,8 @@ emit the following new ones.
...
});
Emitted once the active event counter reaches zero.
Emitted once the active event counter reaches zero and there are no more
steps.
=head1 ATTRIBUTES
Expand All @@ -152,9 +153,9 @@ implements the following new ones.
my $cb = $delay->begin(0);
Increment active event counter, the returned callback can be used to decrement
the active event counter again, all arguments are queued in the right order
for the next step or C<finish> event and C<wait> method. The first argument
passed to the callback will be ignored by default.
the active event counter again. Arguments passed to the callback are queued in
the right order for the next step or C<finish> event and C<wait> method, the
first argument will be ignored by default.
# Capture all arguments
my $delay = Mojo::IOLoop->delay;
Expand All @@ -167,7 +168,8 @@ passed to the callback will be ignored by default.
Sequentialize multiple events, the first callback will run right away, and the
next one once the active event counter reaches zero, this chain will continue
until there are no more callbacks or active events left.
until there are no more callbacks or a callback does not increment the active
event counter.
=head2 wait
Expand Down
6 changes: 3 additions & 3 deletions t/mojo/delay.t
Expand Up @@ -143,15 +143,15 @@ $delay = Mojo::IOLoop->delay(
$end2->(4);
$end3->(5, 6);
$end->(1, 2, 3);
Mojo::IOLoop->timer(0 => $first->begin);
$first->begin(0)->(23);
},
sub {
my ($first, @numbers) = @_;
push @$result, @numbers;
}
);
is_deeply [$delay->wait], [2, 3, 2, 1, 4, 5, 6], 'right numbers';
is_deeply [$delay->wait], [2, 3, 2, 1, 4, 5, 6, 23], 'right numbers';
is $finished, 1, 'finish event has been emitted once';
is_deeply $result, [1, 2, 3, 2, 3, 2, 1, 4, 5, 6], 'right numbers';
is_deeply $result, [1, 2, 3, 2, 3, 2, 1, 4, 5, 6, 23], 'right numbers';

done_testing();

0 comments on commit cd04cd8

Please sign in to comment.