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)||'') eq 'start');
19 return $f if $f->is_ready;
20 require Object::Remote;
21 my $loop = Object::Remote->current_loop;
22 $f->on_ready(sub { $loop->stop });
24 return wantarray ? $f->get : ($f->get)[0];
28 await_future(CPS::Future->needs_all(@_));
36 my ($method) = our $AUTOLOAD =~ /^start::(.+)$/;
38 unless (eval { $res = $invocant->$method(@_); 1 }) {
39 my $f = CPS::Future->new;
43 unless (Scalar::Util::blessed($res) and $res->isa('CPS::Future')) {
44 my $f = CPS::Future->new;
55 my ($method) = our $AUTOLOAD =~ /^maybe::start::(.+)$/;
56 $method = "start::${method}" if ((caller(1)||'') eq 'start');
57 $invocant->$method(@_);
64 my ($method) = our $AUTOLOAD =~ /^then::(.+)$/;
66 # Need two copies since if we're called on an already complete future
67 # $f will be freed immediately
68 my $ret = my $f = CPS::Future->new;
69 $invocant->on_fail(sub { $f->fail(@_); undef($f); });
70 $invocant->on_done(sub {
72 my $next = $obj->${\"start::${method}"}(@args);
73 $next->on_done(sub { $f->done(@_); undef($f); });
74 $next->on_fail(sub { $f->fail(@_); undef($f); });
83 Object::Remote::Future - Asynchronous calling for L<Object::Remote>
87 Shipping prioritised over writing this part up. Blame mst.