From: Matt S Trout Date: Tue, 19 Mar 2013 23:22:09 +0000 (+0000) Subject: simplify then:: code for recent Futures X-Git-Tag: v0.003002~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d002a2eac8f0900b6c5f1387ca4a5ecd8cd8cf42;p=scpubgit%2FObject-Remote.git simplify then:: code for recent Futures --- diff --git a/lib/Object/Remote/Future.pm b/lib/Object/Remote/Future.pm index d8acd3c..83aad96 100644 --- a/lib/Object/Remote/Future.pm +++ b/lib/Object/Remote/Future.pm @@ -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 = 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;