Skip to content

Commit

Permalink
make sure reset stops the event loop
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jun 16, 2014
1 parent 64c1e1a commit 8a587ae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/Mojo/IOLoop.pm
Expand Up @@ -100,10 +100,12 @@ sub remove {

sub reset {
my $self = _instance(shift);

$self->_remove($_)
for keys %{$self->{acceptors}}, keys %{$self->{connections}};
delete @$self{qw(accept stop)};
$self->reactor->reset;
$self->stop;
}

sub server {
Expand Down Expand Up @@ -565,7 +567,7 @@ them to finish writing all data in their write buffers.
Mojo::IOLoop->reset;
$loop->reset;
Remove everything.
Remove everything and stop the event loop.
=head2 server
Expand Down
14 changes: 11 additions & 3 deletions t/mojo/ioloop.t
Expand Up @@ -91,9 +91,16 @@ $id2
= Mojo::IOLoop->client((address => 'localhost', port => $port) => sub { });
Mojo::IOLoop->start;
$count = 0;
Mojo::IOLoop->recurring(0 => sub { $timer++ });
Mojo::IOLoop->reset;
Mojo::IOLoop->one_tick;
Mojo::IOLoop->recurring(10 => sub { $timer++ });
my $running;
Mojo::IOLoop->next_tick(
sub {
Mojo::IOLoop->reset;
$running = Mojo::IOLoop->is_running;
}
);
Mojo::IOLoop->start;
ok !$running, 'not running';
is $count, 0, 'no recurring events';
ok !Mojo::IOLoop->acceptor($id), 'acceptor has been removed';
ok !Mojo::IOLoop->stream($id2), 'stream has been removed';
Expand All @@ -104,6 +111,7 @@ isa_ok $handle, 'IO::Socket', 'right reference';
my $time = time;
Mojo::IOLoop->start;
Mojo::IOLoop->one_tick;
Mojo::IOLoop->reset;
ok time < ($time + 10), 'stopped automatically';

# Stream
Expand Down

0 comments on commit 8a587ae

Please sign in to comment.