Skip to content

Commit

Permalink
fixed error event bug in Mojo::IOLoop::Delay
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Nov 11, 2013
1 parent 9f81d4f commit 11b3693
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changes
@@ -1,6 +1,7 @@

4.57 2013-11-11
- Improved compatibility with IO::Socket::SSL 1.957.
- Fixed error event bug in Mojo::IOLoop::Delay.

4.56 2013-11-09
- Fixed backspace escaping bug in Mojo::JSON. (ig3)
Expand Down
4 changes: 3 additions & 1 deletion lib/Mojo/IOLoop/Delay.pm
Expand Up @@ -23,13 +23,15 @@ sub wait {
my $self = shift;

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

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

sub _die { $_[0]->has_subscribers('error') ? $_[0]->ioloop->stop : die $_[1] }

sub _step {
my ($self, $id) = (shift, shift);

Expand Down
9 changes: 9 additions & 0 deletions t/mojo/delay.t
Expand Up @@ -220,4 +220,13 @@ like $failed, qr/^Second step!/, 'right error';
ok !$finished, 'finish event has not been emitted';
ok !$result, 'no result';

# Fatal exception in second step
Mojo::IOLoop->singleton->reactor->unsubscribe('error');
$delay = Mojo::IOLoop::Delay->new;
ok !$delay->has_subscribers('error'), 'no subscribers';
$delay->steps(sub { Mojo::IOLoop->timer(0 => shift->begin) },
sub { die 'Oops!' });
eval { $delay->wait };
like $@, qr/Oops!/, 'right error';

done_testing();

0 comments on commit 11b3693

Please sign in to comment.