Skip to content

Commit

Permalink
more consistent error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Mar 21, 2015
1 parent 9e4dfb7 commit a51551c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
7 changes: 4 additions & 3 deletions lib/Mojo/Reactor/EV.pm
Expand Up @@ -45,8 +45,9 @@ sub watch {
else {
my $cb = sub {
my ($w, $revents) = @_;
$self->_sandbox('Read', $self->{io}{$fd}{cb}, 0) if EV::READ & $revents;
$self->_sandbox('Write', $self->{io}{$fd}{cb}, 1)
$self->_try('I/O watcher', $self->{io}{$fd}{cb}, 0)
if EV::READ & $revents;
$self->_try('I/O watcher', $self->{io}{$fd}{cb}, 1)
if EV::WRITE & $revents && $self->{io}{$fd};
};
$io->{watcher} = EV::io($fd, $mode, $cb);
Expand All @@ -62,7 +63,7 @@ sub _timer {
my $id = $self->_id;
my $wrapper = sub {
delete $self->{timers}{$id} unless $recurring;
$self->_sandbox('Timer', $cb);
$self->_try('Timer', $cb);
};
EV::now_update() if $after > 0;
$self->{timers}{$id}{watcher} = EV::timer($after, $after, $wrapper);
Expand Down
16 changes: 8 additions & 8 deletions lib/Mojo/Reactor/Poll.pm
Expand Up @@ -48,10 +48,10 @@ sub one_tick {

if ($mode & (POLLIN | POLLPRI | POLLNVAL | POLLHUP | POLLERR)) {
next unless my $io = $self->{io}{$fd};
++$i and $self->_sandbox('Read', $io->{cb}, 0);
++$i and $self->_try('I/O watcher', $io->{cb}, 0);
}
next unless $mode & POLLOUT && (my $io = $self->{io}{$fd});
++$i and $self->_sandbox('Write', $io->{cb}, 1);
++$i and $self->_try('I/O watcher', $io->{cb}, 1);
}
}
}
Expand All @@ -71,7 +71,7 @@ sub one_tick {
# Normal timer
else { $self->remove($id) }

++$i and $self->_sandbox('Timer', $t->{cb}) if $t->{cb};
++$i and $self->_try('Timer', $t->{cb}) if $t->{cb};
}
}
}
Expand Down Expand Up @@ -114,11 +114,6 @@ sub _id {
return $id;
}

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

sub _timer {
my ($self, $recurring, $after, $cb) = @_;

Expand All @@ -130,6 +125,11 @@ sub _timer {
return $id;
}

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

1;

=encoding utf8
Expand Down

0 comments on commit a51551c

Please sign in to comment.