Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
more delay tests
  • Loading branch information
kraih committed Mar 3, 2014
1 parent ddcce0b commit a7ed2b8
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions t/mojo/delay.t
Expand Up @@ -68,7 +68,8 @@ $delay->steps(
sub {
my ($delay, @numbers) = @_;
my $end = $delay->begin;
Mojo::IOLoop->next_tick(sub { $end->(undef, @numbers, 4) });
Mojo::IOLoop->next_tick(
sub { $end->(undef, @numbers, 4)->data(foo => 'bar') });
},
sub {
my ($delay, @numbers) = @_;
Expand All @@ -78,6 +79,7 @@ $delay->steps(
is_deeply [$delay->wait], [2, 3, 2, 1, 4, 5], 'right return values';
is $finished, 1, 'finish event has been emitted once';
is_deeply $result, [2, 3, 2, 1, 4, 5], 'right results';
is $delay->data('foo'), 'bar', 'right value';

# End chain after first step
($finished, $result) = ();
Expand Down Expand Up @@ -228,14 +230,18 @@ $delay = Mojo::IOLoop::Delay->new;
$delay->on(error => sub { $failed = pop });
$delay->on(finish => sub { $finished++ });
$delay->steps(
sub { Mojo::IOLoop->next_tick(shift->begin) },
sub {
my $end = shift->begin;
Mojo::IOLoop->next_tick(sub { $end->()->data(foo => 'bar') });
},
sub { die 'Second step!' },
sub { $result = 'failed' }
);
$delay->wait;
like $failed, qr/^Second step!/, 'right error';
ok !$finished, 'finish event has not been emitted';
ok !$result, 'no result';
is $delay->data('foo'), 'bar', 'right value';

# Exception in second step (with active event)
($failed, $finished, $result) = ();
Expand Down

0 comments on commit a7ed2b8

Please sign in to comment.