Skip to content

Commit

Permalink
mention reactor class in warning
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 29, 2013
1 parent 649ac29 commit 7e172e7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/Mojo/IOLoop.pm
Expand Up @@ -10,7 +10,7 @@ use Mojo::IOLoop::Server;
use Mojo::IOLoop::Stream;
use Mojo::Reactor::Poll;
use Mojo::Util qw(md5_sum steady_time);
use Scalar::Util 'weaken';
use Scalar::Util qw(blessed weaken);

use constant DEBUG => $ENV{MOJO_IOLOOP_DEBUG} || 0;

Expand All @@ -23,7 +23,7 @@ has reactor => sub {
my $class = Mojo::Reactor::Poll->detect;
warn "-- Reactor initialized ($class)\n" if DEBUG;
my $reactor = $class->new;
$reactor->on(error => sub { warn $_[1] });
$reactor->on(error => sub { warn "@{[blessed $_[0]]}: $_[1]" });
return $reactor;
};

Expand Down
6 changes: 3 additions & 3 deletions lib/Mojo/Reactor/EV.pm
Expand Up @@ -49,8 +49,8 @@ sub watch {
sub _io {
my ($self, $fd, $w, $revents) = @_;
my $io = $self->{io}{$fd};
$self->_sandbox('read', $io->{cb}, 0) if EV::READ &$revents;
$self->_sandbox('write', $io->{cb}, 1)
$self->_sandbox('Read', $io->{cb}, 0) if EV::READ &$revents;
$self->_sandbox('Write', $io->{cb}, 1)
if EV::WRITE &$revents && $self->{io}{$fd};
}

Expand All @@ -62,7 +62,7 @@ sub _timer {
weaken $self;
$self->{timers}{$id}{watcher} = EV::timer(
$after => $after => sub {
$self->_sandbox("timer $id", $self->{timers}{$id}{cb});
$self->_sandbox("Timer $id", $self->{timers}{$id}{cb});
delete $self->{timers}{$id} unless $recurring;
}
);
Expand Down
9 changes: 4 additions & 5 deletions lib/Mojo/Reactor/Poll.pm
Expand Up @@ -42,9 +42,9 @@ sub one_tick {
# I/O
if (keys %{$self->{io}}) {
$poll->poll($timeout);
++$i and $self->_sandbox('read', $self->{io}{fileno $_}{cb}, 0)
++$i and $self->_sandbox('Read', $self->{io}{fileno $_}{cb}, 0)
for $poll->handles(POLLIN | POLLHUP | POLLERR);
++$i and $self->_sandbox('write', $self->{io}{fileno $_}{cb}, 1)
++$i and $self->_sandbox('Write', $self->{io}{fileno $_}{cb}, 1)
for $poll->handles(POLLOUT);
}

Expand All @@ -63,7 +63,7 @@ sub one_tick {
# Normal timer
else { $self->remove($id) }

++$i and $self->_sandbox("timer $id", $t->{cb}) if $t->{cb};
++$i and $self->_sandbox("Timer $id", $t->{cb}) if $t->{cb};
}
}

Expand Down Expand Up @@ -106,8 +106,7 @@ sub _poll { shift->{poll} ||= IO::Poll->new }

sub _sandbox {
my ($self, $event, $cb) = (shift, shift, shift);
$self->emit(error => "Reactor $event failed: $@")
unless eval { $self->$cb(@_); 1 };
eval { $self->$cb(@_); 1 } or $self->emit(error => "$event failed: $@");
}

sub _timer {
Expand Down
2 changes: 1 addition & 1 deletion t/mojo/ioloop.t
Expand Up @@ -264,7 +264,7 @@ is $loop->max_accepts, 1, 'right value';
my $loop = Mojo::IOLoop->new;
$loop->timer(0 => sub { die 'Bye!' });
$loop->start;
like $err, qr/Bye!/, 'right error';
like $err, qr/^MyReactor:.*Bye!/, 'right error';
}

# Defaults
Expand Down

0 comments on commit 7e172e7

Please sign in to comment.