Skip to content

Commit

Permalink
Move the exit_guard to register_service so AE::cv->recv (without ->ru…
Browse files Browse the repository at this point in the history
…n) would work.
  • Loading branch information
miyagawa committed Feb 18, 2010
1 parent 2d065bd commit 0642ce7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
3 changes: 2 additions & 1 deletion lib/Twiggy.pm
Expand Up @@ -24,7 +24,8 @@ See C<twiggey -h> for more details.
port => $port,
);
$server->register_service($app);
$server->run;
AE::cv->recv;
=head1 DESCRIPTION
Expand Down
18 changes: 9 additions & 9 deletions lib/Twiggy/Server.pm
Expand Up @@ -46,6 +46,13 @@ sub register_service {
for my $listen (@listen) {
push @{$self->{listen_guards}}, $self->_create_tcp_server($listen, $app);
}

$self->{exit_guard} = AE::cv {
# Make sure that we are not listening on a socket anymore, while
# other events are being flushed
delete $self->{listen_guards};
};
$self->{exit_guard}->begin;
}

sub _create_tcp_server {
Expand Down Expand Up @@ -544,15 +551,8 @@ sub run {
my $self = shift;
$self->register_service(@_);

my $exit = $self->{exit_guard} = AE::cv {
# Make sure that we are not listening on a socket anymore, while
# other events are being flushed
delete $self->{listen_guards};
};
$exit->begin;

my $w; $w = AE::signal QUIT => sub { $exit->end; undef $w };
$exit->recv;
my $w; $w = AE::signal QUIT => sub { $self->{exit_guard}->end; undef $w };
$self->{exit_guard}->recv;
}

package Twiggy::Writer;
Expand Down

0 comments on commit 0642ce7

Please sign in to comment.