From: Matt S Trout Date: Mon, 11 Jun 2012 21:15:14 +0000 (+0100) Subject: split want_run versus blocking run for ::Future X-Git-Tag: v0.001001~23 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2FObject-Remote.git;a=commitdiff_plain;h=6c597351edfa3ed86fc06b7be3165b334bf93784 split want_run versus blocking run for ::Future --- diff --git a/bin/object-remote-node b/bin/object-remote-node index 1ab639d..ed1ba32 100755 --- a/bin/object-remote-node +++ b/bin/object-remote-node @@ -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; diff --git a/lib/Object/Remote/MiniLoop.pm b/lib/Object/Remote/MiniLoop.pm index c5025f3..b74619c 100644 --- a/lib/Object/Remote/MiniLoop.pm +++ b/lib/Object/Remote/MiniLoop.pm @@ -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;