Navigation Menu

Skip to content

Commit

Permalink
better next_tick tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 26, 2015
1 parent 5a5e485 commit 13bc2ca
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
3 changes: 2 additions & 1 deletion lib/Mojo/Reactor.pm
Expand Up @@ -31,7 +31,8 @@ sub watch { croak 'Method "watch" not implemented by subclass' }

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

1;
Expand Down
10 changes: 4 additions & 6 deletions t/mojo/reactor_ev.t
Expand Up @@ -150,13 +150,11 @@ is ref $reactor2, 'Mojo::Reactor::Poll', 'right object';

# Ordered next_tick
my $result = [];
$reactor->next_tick(sub { push @$result, 1 });
$reactor->next_tick(sub { push @$result, 2 });
$reactor->next_tick(sub { push @$result, 3 });
$reactor->next_tick(sub { push @$result, 4 });
$reactor->next_tick(sub { push @$result, 5 });
for my $i (1 .. 50) {
$reactor->next_tick(sub { push @$result, $i });
}
$reactor->start;
is_deeply $result, [1, 2, 3, 4, 5], 'right result';
is_deeply $result, [1 .. 50], 'right result';

# Reset while watchers are active
$writable = undef;
Expand Down
10 changes: 4 additions & 6 deletions t/mojo/reactor_poll.t
Expand Up @@ -147,13 +147,11 @@ is ref $reactor2, 'Mojo::Reactor::Poll', 'right object';

# Ordered next_tick
my $result = [];
$reactor->next_tick(sub { push @$result, 1 });
$reactor->next_tick(sub { push @$result, 2 });
$reactor->next_tick(sub { push @$result, 3 });
$reactor->next_tick(sub { push @$result, 4 });
$reactor->next_tick(sub { push @$result, 5 });
for my $i (1 .. 50) {
$reactor->next_tick(sub { push @$result, $i });
}
$reactor->start;
is_deeply $result, [1, 2, 3, 4, 5], 'right result';
is_deeply $result, [1 .. 50], 'right result';

# Reset while watchers are active
$writable = undef;
Expand Down

0 comments on commit 13bc2ca

Please sign in to comment.