Skip to content

Commit

Permalink
fixed portability bug in Mojo::IOLoop::Delay
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Sep 7, 2013
1 parent 873ea09 commit af43379
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,5 +1,6 @@

4.33 2013-09-08
4.33 2013-09-07
- Fixed portability bug in Mojo::IOLoop::Delay.

4.32 2013-09-06
- Added error event to Mojo::IOLoop::Delay.
Expand Down
9 changes: 5 additions & 4 deletions lib/Mojo/IOLoop/Delay.pm
Expand Up @@ -22,12 +22,12 @@ sub steps {
sub wait {
my $self = shift;

my ($err, @args);
$self->once(error => sub { shift->ioloop->stop; $err = shift });
my @args;
$self->once(error => sub { shift->ioloop->stop });
$self->once(finish => sub { shift->ioloop->stop; @args = @_ });
$self->ioloop->start;

return defined $err ? die $err : wantarray ? @args : $args[0];
return wantarray ? @args : $args[0];
}

sub _step {
Expand Down Expand Up @@ -170,7 +170,8 @@ event counter or an error occurs in a callback.
=head2 wait
my @args = $delay->wait;
my @args = $delay->wait;
my $first = $delay->wait;
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.
Expand Down
9 changes: 3 additions & 6 deletions t/mojo/delay.t
Expand Up @@ -170,8 +170,7 @@ $delay = Mojo::IOLoop::Delay->new;
$delay->on(error => sub { $failed = pop });
$delay->on(finish => sub { $finished++ });
$delay->steps(sub { die 'First step!' }, sub { $result = 'failed' });
eval { $delay->wait };
like $@, qr/^First step!/, 'right error';
is_deeply [$delay->wait], [], 'no return values';
like $failed, qr/^First step!/, 'right error';
ok !$finished, 'finish event has not been emitted';
ok !$result, 'no result';
Expand All @@ -183,8 +182,7 @@ $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';
is scalar $delay->wait, undef, 'no return value';
like $failed, qr/^Last step!/, 'right error';
ok !$finished, 'finish event has not been emitted';

Expand All @@ -198,8 +196,7 @@ $delay->steps(
sub { die 'Second step!' },
sub { $result = 'failed' }
);
eval { $delay->wait };
like $@, qr/^Second step!/, 'right error';
$delay->wait;
like $failed, qr/^Second step!/, 'right error';
ok !$finished, 'finish event has not been emitted';
ok !$result, 'no result';
Expand Down

0 comments on commit af43379

Please sign in to comment.