Skip to content

Commit

Permalink
more delay tests and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Sep 6, 2013
1 parent 8f76007 commit e7f42ef
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lib/Mojo/IOLoop/Delay.pm
Expand Up @@ -116,8 +116,7 @@ emit the following new ones.
...
});
Emitted if an error occurs in one of the steps and no more steps will be
reached.
Emitted if an error occurs in one of the steps, breaking the chain.
=head2 finish
Expand Down Expand Up @@ -166,16 +165,16 @@ first argument will be ignored by default.
$delay = $delay->steps(sub {...}, sub {...});
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 a callback does not increment the active
event counter.
next one once the active event counter reaches zero. This chain will continue
until there are no more callbacks, a callback does not increment the active
event counter or an error occurs in a callback.
=head2 wait
my @args = $delay->wait;
Start C<ioloop> and stop it again once the C<finish> event gets emitted, only
works when C<ioloop> is not running already.
Start C<ioloop> and stop it again once an C<error> or C<finish> event gets
emitted, only works when C<ioloop> is not running already.
# Use the "finish" event to synchronize portably
$delay->on(finish => sub {
Expand Down
12 changes: 12 additions & 0 deletions t/mojo/delay.t
Expand Up @@ -176,6 +176,18 @@ like $failed, qr/^First step!/, 'right error';
ok !$finished, 'finish event has not been emitted';
ok !$result, 'no result';

# Exception in last step
($failed, $finished) = ();
$delay = Mojo::IOLoop::Delay->new;
$delay->on(error => sub { $failed = pop });
$delay->on(finish => sub { $finished++ });
$delay->steps(sub { Mojo::IOLoop->timer(0 => shift->begin) },
sub { die 'Last step!' });
eval { $delay->wait };
like $@, qr/^Last step!/, 'right error';
like $failed, qr/^Last step!/, 'right error';
ok !$finished, 'finish event has not been emitted';

# Exception in second step
($failed, $finished, $result) = ();
$delay = Mojo::IOLoop::Delay->new;
Expand Down

0 comments on commit e7f42ef

Please sign in to comment.