Commit c1e56c8e authored by Michael Pyne's avatar Michael Pyne

mojo: Improve dep tree generator to use fewer promises.

parent 96d5e871
Pipeline #7600 passed with stage
in 1 minute and 28 seconds
......@@ -79,55 +79,37 @@ sub _check_error {
die $err;
};
sub _fetchModuleList
{
my ($ua, $list) = @_;
return $ua->get_p($list)->then(sub {
my $tx = _check_error(shift);
return $tx->result->json;
});
}
sub dumpDependencyTree
{
my ($ua, $tree) = @_;
#
# TODO: this could fail, how to properly promisify?
#
my $errors = $tree->{errors} // {};
my $errorCount = $errors->{errors} // 0;
if ($errorCount != 0) {
say "Unable to resolve dependencies, number of errors encountered is: $errorCount";
my $p = Mojo::Promise->new();
return $p->resolve(1);
say "Unable to resolve dependencies, encountered $errorCount errors";
return Mojo::Promise->new->reject(1);
}
my $data = $tree->{data};
if (!defined($data)) {
say "Unable to resolve dependencies, did not obtain (valid) results";
my $p = Mojo::Promise->new();
return $p->resolve(1);
}
else {
#
# TODO: this is *not* how we should await things in general.
# Fix using Mojo::AsyncAwait?
#
return _fetchModuleList($ua, '/modulesFromCommand')->then(sub {
my $list = shift;
my @names = map { $_->{name} } (@$list);
return @names;
})->then(sub {
my @modules = @_;
my $err = ksb::UserInterface::DependencyGraph::printTrees(
$data,
@modules
);
return $err ? 1 : 0;
});
return Mojo::Promise->new->reject(1);
}
return $ua->get_p('/modulesFromCommand')->then(sub {
my $tx = _check_error(shift);
my @modules = map { $_->{name} } @{$tx->result->json};
my $err = ksb::UserInterface::DependencyGraph::printTrees(
$data,
@modules
);
return Mojo::Promise->new->reject(1)
if $err;
return 0;
});
}
# Returns a promise chain to handle the "debug and show some output but don't
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment