Subject: | ->finally ? |
I have a use case where I don't really care whether a Future failed or not; I just want the result.
The sample code below tries to report on the results of the forked processes, which ->fail if there was a nonzero exit code. As a result, I have to extract the data from the Future first.
A ->finally method could perform this job, i.e. to ignore the actual error in a failed Future, and simply run the code with the rest of the failure data as the return value of the operation itself.
--
use App::Multigit qw(mg_each);
use curry;
sub extract_future {
my $f = shift;
my @result;
if ($f->failure) {
(undef, @result) = $f->failure;
}
else {
@result = $f->get;
}
Future->done(@result);
}
mg_each(sub{
my $repo = shift;
$repo->run([qw/ this command might fail /])
->followed_by(\&extract_future)
->then($repo->curry::report)
});
--
use App::Multigit qw/mg_each/;
use curry;
mg_each(sub{
my $repo = shift;
$repo->run([qw/ this command might fail /])
->finally($repo->curry::report)
});