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)
};
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;
}
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);
return wantarray ? $f->get : ($f->get)[0];
}
+sub await_all {
+ await_future(CPS::Future->needs_all(@_));
+ map $_->get, @_;
+}
+
package start;
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;
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 { }