X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2FObject-Remote.git;a=blobdiff_plain;f=lib%2FObject%2FRemote%2FFuture.pm;h=83aad963a4f4eab9b24cc5273c86170a213ffd14;hp=570bbb5d824569f8908e9ea8d1edb6d7824b10f8;hb=d002a2eac8f0900b6c5f1387ca4a5ecd8cd8cf42;hpb=4e4463355a9ec6afdc7983ee36daa9f11306d4fc diff --git a/lib/Object/Remote/Future.pm b/lib/Object/Remote/Future.pm index 570bbb5..83aad96 100644 --- a/lib/Object/Remote/Future.pm +++ b/lib/Object/Remote/Future.pm @@ -4,16 +4,16 @@ use strict; use warnings; use base qw(Exporter); -use Object::Remote::Logging qw( :log get_router ); +use Object::Remote::Logging qw( :log router ); -BEGIN { get_router()->exclude_forwarding } +BEGIN { router()->exclude_forwarding } -use CPS::Future; +use Future; our @EXPORT = qw(future await_future await_all); sub future (&;$) { - my $f = $_[0]->(CPS::Future->new); + my $f = $_[0]->(Future->new); return $f if ((caller(1+($_[1]||0))||'') eq 'start'); await_future($f); } @@ -32,7 +32,7 @@ sub await_future { log_trace { my $l = @await; "future has become ready, length of \@await: '$l'" }; if ($f == $await[-1]) { log_trace { "This future is not waiting on anything so calling stop on the run loop" }; - $loop->stop; + $loop->stop; } }); log_trace { "Starting run loop for newly created future" }; @@ -48,7 +48,7 @@ sub await_future { sub await_all { log_trace { my $l = @_; "await_all() invoked with '$l' futures to wait on" }; - await_future(CPS::Future->wait_all(@_)); + await_future(Future->wait_all(@_)); map $_->get, @_; } @@ -61,12 +61,12 @@ sub AUTOLOAD { my ($method) = our $AUTOLOAD =~ /^start::(.+)$/; my $res; unless (eval { $res = $invocant->$method(@_); 1 }) { - my $f = CPS::Future->new; + my $f = Future->new; $f->fail($@); return $f; } - unless (Scalar::Util::blessed($res) and $res->isa('CPS::Future')) { - my $f = CPS::Future->new; + unless (Scalar::Util::blessed($res) and $res->isa('Future')) { + my $f = Future->new; $f->done($res); return $f; } @@ -99,17 +99,10 @@ sub AUTOLOAD { my $invocant = shift; my ($method) = our $AUTOLOAD =~ /^then::(.+)$/; my @args = @_; - # Need two copies since if we're called on an already complete future - # $f will be freed immediately - my $ret = my $f = CPS::Future->new; - $invocant->on_fail(sub { $f->fail(@_); undef($f); }); - $invocant->on_done(sub { - my ($obj) = @_; - my $next = $obj->${\"start::${method}"}(@args); - $next->on_done(sub { $f->done(@_); undef($f); }); - $next->on_fail(sub { $f->fail(@_); undef($f); }); + return $invocant->and_then(sub { + my ($obj) = $_[0]->get; + return $obj->${\"start::${method}"}(@args); }); - return $ret; } 1;