1 package Object::Remote::Future;
9 our @EXPORT = qw(future await_future await_all);
12 my $f = $_[0]->(CPS::Future->new);
13 return $f if ((caller(1+($_[1]||0))||'') eq 'start');
21 return $f if $f->is_ready;
22 require Object::Remote;
23 my $loop = Object::Remote->current_loop;
25 local @await = (@await, $f);
27 $loop->stop if $f == $await[-1]
31 if (@await and $await[-1]->is_ready) {
34 return wantarray ? $f->get : ($f->get)[0];
38 await_future(CPS::Future->wait_all(@_));
44 our $start = sub { my ($obj, $call) = (shift, shift); $obj->$call(@_); };
48 my ($method) = our $AUTOLOAD =~ /^start::(.+)$/;
50 unless (eval { $res = $invocant->$method(@_); 1 }) {
51 my $f = CPS::Future->new;
55 unless (Scalar::Util::blessed($res) and $res->isa('CPS::Future')) {
56 my $f = CPS::Future->new;
66 my ($obj, $call) = (shift, shift);
67 if ((caller(1)||'') eq 'start') {
68 $obj->$start::start($call => @_);
78 my ($method) = our $AUTOLOAD =~ /^maybe::start::(.+)$/;
79 $method = "start::${method}" if ((caller(1)||'') eq 'start');
80 $invocant->$method(@_);
87 my ($method) = our $AUTOLOAD =~ /^then::(.+)$/;
89 # Need two copies since if we're called on an already complete future
90 # $f will be freed immediately
91 my $ret = my $f = CPS::Future->new;
92 $invocant->on_fail(sub { $f->fail(@_); undef($f); });
93 $invocant->on_done(sub {
95 my $next = $obj->${\"start::${method}"}(@args);
96 $next->on_done(sub { $f->done(@_); undef($f); });
97 $next->on_fail(sub { $f->fail(@_); undef($f); });
106 Object::Remote::Future - Asynchronous calling for L<Object::Remote>
110 Shipping prioritised over writing this part up. Blame mst.