diff options
Diffstat (limited to 'src/libstore/build/goal.cc')
-rw-r--r-- | src/libstore/build/goal.cc | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/src/libstore/build/goal.cc b/src/libstore/build/goal.cc index cfdb6717c..02b22b8ad 100644 --- a/src/libstore/build/goal.cc +++ b/src/libstore/build/goal.cc @@ -1,6 +1,7 @@ #include "goal.hh" #include "async-collect.hh" #include "worker.hh" +#include <boost/outcome/try.hpp> #include <kj/time.h> namespace nix { @@ -11,45 +12,60 @@ void Goal::trace(std::string_view s) debug("%1%: %2%", name, s); } -kj::Promise<Result<Goal::WorkResult>> Goal::waitForAWhile() -try { +kj::Promise<void> Goal::waitForAWhile() +{ trace("wait for a while"); /* If we are polling goals that are waiting for a lock, then wake up after a few seconds at most. */ - co_await worker.aio.provider->getTimer().afterDelay(settings.pollInterval.get() * kj::SECONDS); - co_return StillAlive{}; + return worker.aio.provider->getTimer().afterDelay(settings.pollInterval.get() * kj::SECONDS); +} + +kj::Promise<Result<Goal::WorkResult>> Goal::work() noexcept +try { + BOOST_OUTCOME_CO_TRY(auto result, co_await workImpl()); + + trace("done"); + + cleanup(); + + co_return std::move(result); } catch (...) { - co_return std::current_exception(); + co_return result::failure(std::current_exception()); } -kj::Promise<Result<Goal::WorkResult>> -Goal::waitForGoals(kj::Array<std::pair<GoalPtr, kj::Promise<void>>> dependencies) noexcept +kj::Promise<Result<void>> +Goal::waitForGoals(kj::Array<std::pair<GoalPtr, kj::Promise<Result<WorkResult>>>> dependencies) noexcept try { auto left = dependencies.size(); for (auto & [dep, p] : dependencies) { - p = p.then([this, dep, &left] { + p = p.then([this, dep, &left](auto _result) -> Result<WorkResult> { + BOOST_OUTCOME_TRY(auto result, _result); + left--; trace(fmt("waitee '%s' done; %d left", dep->name, left)); - if (dep->exitCode != Goal::ecSuccess) ++nrFailed; - if (dep->exitCode == Goal::ecNoSubstituters) ++nrNoSubstituters; - if (dep->exitCode == Goal::ecIncompleteClosure) ++nrIncompleteClosure; + if (result.exitCode != Goal::ecSuccess) ++nrFailed; + if (result.exitCode == Goal::ecNoSubstituters) ++nrNoSubstituters; + if (result.exitCode == Goal::ecIncompleteClosure) ++nrIncompleteClosure; + + return std::move(result); }).eagerlyEvaluate(nullptr); } auto collectDeps = asyncCollect(std::move(dependencies)); while (auto item = co_await collectDeps.next()) { - auto & dep = *item; + auto & [dep, _result] = *item; + BOOST_OUTCOME_CO_TRY(auto result, _result); waiteeDone(dep); - if (dep->exitCode == ecFailed && !settings.keepGoing) { - co_return result::success(StillAlive{}); + if (result.exitCode == ecFailed && !settings.keepGoing) { + co_return result::success(); } } - co_return result::success(StillAlive{}); + co_return result::success(); } catch (...) { co_return result::failure(std::current_exception()); } |