split want_run versus blocking run for ::Future
Matt S Trout [Mon, 11 Jun 2012 21:15:14 +0000 (22:15 +0100)]
bin/object-remote-node
lib/Object/Remote/MiniLoop.pm

index 1ab639d..ed1ba32 100755 (executable)
@@ -13,10 +13,11 @@ my $loop = Object::Remote->current_loop;
 
 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;
index c5025f3..b74619c 100644 (file)
@@ -50,6 +50,21 @@ sub loop_once {
   }
 }
 
+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;