start and await_all working
[scpubgit/Object-Remote.git] / lib / Object / Remote / Future.pm
index 2fe171b..11850d6 100644 (file)
@@ -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;