Skip to content

Commit

Permalink
there is no need for stop_gracefully to be slow
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Mar 2, 2016
1 parent 912bfac commit 7eb7346
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,5 +1,6 @@

6.52 2016-03-02
- Improved responsiveness of stop_gracefully method in Mojo::IOLoop.
- Fixed a few concurrency bugs in Mojo::IOLoop.

6.51 2016-02-29
Expand Down
10 changes: 3 additions & 7 deletions lib/Mojo/IOLoop.pm
Expand Up @@ -138,7 +138,7 @@ sub stop { _instance(shift)->reactor->stop }

sub stop_gracefully {
my $self = _instance(shift)->_not_accepting;
$self->{stop} ||= $self->emit('finish')->recurring(1 => \&_stop);
++$self->{stop} and $self->emit('finish')->_stop;
}

sub stream {
Expand Down Expand Up @@ -193,16 +193,12 @@ sub _remove {

# Connection
return unless delete $self->{in}{$id} || delete $self->{out}{$id};
$self->_stop if $self->{stop};
$self->_maybe_accepting;
warn "-- $id <<< $$ (@{[$self->_in]}:@{[$self->_out]})\n" if DEBUG;
}

sub _stop {
my $self = shift;
return if $self->_out || $self->_in;
$self->_remove(delete $self->{stop});
$self->stop;
}
sub _stop { !$_[0]->_out && !$_[0]->_in && $_[0]->stop }

sub _stream {
my ($self, $stream, $id, $server) = @_;
Expand Down
2 changes: 1 addition & 1 deletion t/mojo/ioloop.t
Expand Up @@ -261,7 +261,7 @@ $err = '';
$loop = Mojo::IOLoop->new;
my $finish;
$loop->on(finish => sub { $finish++ });
$loop->stop_gracefully;
$loop->next_tick(sub { shift->stop_gracefully });
$loop->remove(
$loop->client({port => Mojo::IOLoop::Server->generate_port} => sub { }));
$loop->timer(30 => sub { shift->stop; $err = 'failed' });
Expand Down

0 comments on commit 7eb7346

Please sign in to comment.