my $f = CPS::Future->new;
-$f->on_ready(sub { $loop->stop });
+$f->on_ready(sub { $loop->want_stop });
$c->on_close($f);
print { $c->send_to_fh } "Shere\n";
-$loop->run;
+$loop->want_run;
+$loop->run_while_wanted;
}
}
+sub want_run {
+ my ($self) = @_;
+ $self->{want_running}++;
+}
+
+sub run_while_wanted {
+ my ($self) = @_;
+ $self->loop_once while $self->{want_running};
+}
+
+sub want_stop {
+ my ($self) = @_;
+ $self->{want_running}-- if $self->{want_running};
+}
+
sub run {
my ($self) = @_;
local $self->{is_running} = 1;