X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FObject%2FRemote%2FFuture.pm;h=3a2643b7f9ac700e8352ca17a39c4cfe87eec2f0;hb=8c81a0e51d629a4f53975c6f738aa14d680b73c1;hp=2fe171b192869e98dbfd900e9b56d9df8ccf47c4;hpb=dc28afe80b27f0eb81eef66e6ba554a7c1fb6e41;p=scpubgit%2FObject-Remote.git diff --git a/lib/Object/Remote/Future.pm b/lib/Object/Remote/Future.pm index 2fe171b..3a2643b 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,11 +24,16 @@ 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 { my $invocant = shift; - my ($method) = our $AUTOLOAD =~ /([^:]+)$/; + my ($method) = our $AUTOLOAD =~ /^start::(.+)$/; if (ref($invocant) eq 'ARRAY') { return [ map $_->${\"start::${method}"}, @$invocant ]; } @@ -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;