Skip to content

Commit

Permalink
fixed recursion bug in Mojo::Reactor::EV where timers could run more …
Browse files Browse the repository at this point in the history
…than once
  • Loading branch information
kraih committed Nov 16, 2013
1 parent 983db7f commit 532ed95
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Changes
@@ -1,6 +1,8 @@

4.58 2013-11-14
4.58 2013-11-16
- Improved IIS and WebSphere compatibility of Mojo::Message::Request.
- Fixed recursion bug in Mojo::Reactor::EV where timers could run more than
once.

4.57 2013-11-11
- Improved compatibility with IO::Socket::SSL 1.957.
Expand Down
5 changes: 3 additions & 2 deletions lib/Mojo/Reactor/EV.pm
Expand Up @@ -62,8 +62,9 @@ sub _timer {
weaken $self;
$self->{timers}{$id}{watcher} = EV::timer(
$after => $after => sub {
$self->_sandbox("Timer $id", $self->{timers}{$id}{cb});
delete $self->{timers}{$id} unless $recurring;
my $timer = $self->{timers}{$id};
delete delete($self->{timers}{$id})->{watcher} unless $recurring;
$self->_sandbox("Timer $id", $timer->{cb});
}
);

Expand Down
7 changes: 7 additions & 0 deletions t/mojo/reactor_ev.t
Expand Up @@ -212,6 +212,13 @@ $reactor->timer(0 => sub { die "works!\n" });
$reactor->start;
like $err, qr/works!/, 'right error';

# Recursion
$timer = undef;
$reactor = $reactor->new;
$reactor->timer(0 => sub { ++$timer and shift->one_tick });
$reactor->one_tick;
is $timer, 1, 'timer was triggered once';

# Detection
is(Mojo::Reactor->detect, 'Mojo::Reactor::EV', 'right class');

Expand Down
7 changes: 7 additions & 0 deletions t/mojo/reactor_poll.t
Expand Up @@ -210,6 +210,13 @@ $reactor->timer(0 => sub { die "works!\n" });
$reactor->start;
like $err, qr/works!/, 'right error';

# Recursion
$timer = undef;
$reactor = $reactor->new;
$reactor->timer(0 => sub { ++$timer and shift->one_tick });
$reactor->one_tick;
is $timer, 1, 'timer was triggered once';

# Detection
is(Mojo::Reactor::Poll->detect, 'Mojo::Reactor::Poll', 'right class');

Expand Down

0 comments on commit 532ed95

Please sign in to comment.