From: Matt S Trout Date: Fri, 18 May 2012 00:18:48 +0000 (+0000) Subject: start and await_all working X-Git-Tag: v0.001001~56 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3f1f1e662b0737ba6225973b88f2d78dd2344314;p=scpubgit%2FObject-Remote.git start and await_all working --- diff --git a/lib/Object/Remote.pm b/lib/Object/Remote.pm index 25f0349..680197e 100644 --- a/lib/Object/Remote.pm +++ b/lib/Object/Remote.pm @@ -59,6 +59,7 @@ sub current_loop { sub call { my ($self, $method, @args) = @_; my $w = wantarray; + $method = "start::${method}" if (caller(0)||'') eq 'start'; future { $self->connection->send(call => $self->id, $w, $method, @args) }; diff --git a/lib/Object/Remote/Connection.pm b/lib/Object/Remote/Connection.pm index 3b66cd5..f69275d 100644 --- a/lib/Object/Remote/Connection.pm +++ b/lib/Object/Remote/Connection.pm @@ -204,6 +204,7 @@ sub _invoke { if ($method =~ /^start::/) { my $f = $local->$method(@args); $f->on_done(sub { undef($f); $future->done(@_) }); + return unless $f; $f->on_fail(sub { undef($f); $future->fail(@_) }); return; } diff --git a/lib/Object/Remote/Future.pm b/lib/Object/Remote/Future.pm index 2fe171b..11850d6 100644 --- a/lib/Object/Remote/Future.pm +++ b/lib/Object/Remote/Future.pm @@ -6,7 +6,7 @@ use base qw(Exporter); use CPS::Future; -our @EXPORT = qw(future await_future); +our @EXPORT = qw(future await_future await_all); sub future (&) { my $f = $_[0]->(CPS::Future->new); @@ -24,6 +24,11 @@ sub await_future { return wantarray ? $f->get : ($f->get)[0]; } +sub await_all { + await_future(CPS::Future->needs_all(@_)); + map $_->get, @_; +} + package start; sub AUTOLOAD { @@ -46,15 +51,4 @@ sub AUTOLOAD { return $res; } -package await; - -sub AUTOLOAD { - my $invocant = shift; - my ($method) = our $AUTOLOAD =~ /([^:]+)$/; - my @invocants = (ref($invocant) eq 'ARRAY' ? @$invocant : $invocant); - my @futures = map $_->${\"start::${method}"}, @$invocant; - Object::Remote::Future::await_future(CPS::Future->needs_all(@futures)); - return map $_->get, @futures; -} - 1; diff --git a/lib/Object/Remote/Proxy.pm b/lib/Object/Remote/Proxy.pm index af6a902..3c46eeb 100644 --- a/lib/Object/Remote/Proxy.pm +++ b/lib/Object/Remote/Proxy.pm @@ -5,10 +5,11 @@ use strictures 1; sub AUTOLOAD { my $self = shift; (my $method) = (our $AUTOLOAD =~ /([^:]+)$/); + my $to_fire = $self->{method}; if ((caller(0)||'') eq 'start') { - $method = "start::${method}"; + $to_fire = "start::${to_fire}"; } - $self->{remote}->${\$self->{method}}($method => @_); + $self->{remote}->$to_fire($method => @_); } sub DESTROY { }