Skip to content

Commit

Permalink
test reset with next_tick
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 27, 2015
1 parent 8d28581 commit 2c26e31
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 deletions lib/Mojo/Reactor/Poll.pm
Expand Up @@ -23,7 +23,7 @@ sub is_running { !!shift->{running} }
sub next_tick {
my ($self, $cb) = @_;
push @{$self->{next_tick}}, $cb;
$self->{next} //= $self->timer(0 => \&_tick);
$self->{next_timer} //= $self->timer(0 => \&_next);
return undef;
}

Expand Down Expand Up @@ -91,7 +91,7 @@ sub remove {
return !!delete $self->{io}{fileno $remove};
}

sub reset { delete @{shift()}{qw(io next next_tick timers)} }
sub reset { delete @{shift()}{qw(io next_tick next_timer timers)} }

sub start {
my $self = shift;
Expand Down Expand Up @@ -121,9 +121,9 @@ sub _id {
return $id;
}

sub _tick {
sub _next {
my $self = shift;
delete $self->{next};
delete $self->{next_timer};
while (my $cb = shift @{$self->{next_tick}}) { $self->$cb }
}

Expand Down
3 changes: 2 additions & 1 deletion t/mojo/reactor_ev.t
Expand Up @@ -138,9 +138,10 @@ ok !$timer, 'timer was not triggered';
ok $recurring, 'recurring was triggered again';

# Reset
$reactor->next_tick(sub { die 'Reset failed' });
$reactor->reset;
($readable, $writable, $recurring) = ();
$reactor->timer(0.025 => sub { shift->stop });
$reactor->next_tick(sub { shift->stop });
$reactor->start;
ok !$readable, 'io event was not triggered again';
ok !$writable, 'io event was not triggered again';
Expand Down
3 changes: 2 additions & 1 deletion t/mojo/reactor_poll.t
Expand Up @@ -135,9 +135,10 @@ ok !$timer, 'timer was not triggered';
ok $recurring, 'recurring was triggered again';

# Reset
$reactor->next_tick(sub { die 'Reset failed' });
$reactor->reset;
($readable, $writable, $recurring) = ();
$reactor->timer(0.025 => sub { shift->stop });
$reactor->next_tick(sub { shift->stop });
$reactor->start;
ok !$readable, 'io event was not triggered again';
ok !$writable, 'io event was not triggered again';
Expand Down

0 comments on commit 2c26e31

Please sign in to comment.