From 5f1344dd8aec59ce654a0fac30b1842e2e68299c Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Sun, 20 Oct 2024 22:55:00 +0200 Subject: libstore: turn Worker::run into a promise a first little step into pushing the event loops up, up and away. eventually we will want them to be instantiated only at the roots of every thread (since kj binds loops to threads), but not today. Change-Id: Ic97f1debba382a5a3f46daeaf2d6d434ee42569f --- src/libstore/build/entry-points.cc | 12 ++++++------ src/libstore/build/worker.cc | 8 +++++--- src/libstore/build/worker.hh | 18 +++++++++++------- 3 files changed, 22 insertions(+), 16 deletions(-) (limited to 'src/libstore') diff --git a/src/libstore/build/entry-points.cc b/src/libstore/build/entry-points.cc index f7669db5d..36ad35be0 100644 --- a/src/libstore/build/entry-points.cc +++ b/src/libstore/build/entry-points.cc @@ -15,7 +15,7 @@ void Store::buildPaths(const std::vector & reqs, BuildMode buildMod for (auto & br : reqs) goals.emplace_back(gf.makeGoal(br, buildMode)); return goals; - }); + }).wait(aio.waitScope).value(); StringSet failed; std::shared_ptr ex; @@ -54,7 +54,7 @@ std::vector Store::buildPathsWithResults( goals.emplace_back(gf.makeGoal(req, buildMode)); } return goals; - }).goals; + }).wait(aio.waitScope).value().goals; std::vector results; @@ -74,7 +74,7 @@ BuildResult Store::buildDerivation(const StorePath & drvPath, const BasicDerivat Worker::Targets goals; goals.emplace_back(gf.makeBasicDerivationGoal(drvPath, drv, OutputsSpec::All{}, buildMode)); return goals; - }); + }).wait(aio.waitScope).value(); auto & result = results.goals.begin()->second; return result.result.restrictTo(DerivedPath::Built { .drvPath = makeConstantStorePathRef(drvPath), @@ -100,7 +100,7 @@ void Store::ensurePath(const StorePath & path) Worker::Targets goals; goals.emplace_back(gf.makePathSubstitutionGoal(path)); return goals; - }); + }).wait(aio.waitScope).value(); auto & result = results.goals.begin()->second; if (result.exitCode != Goal::ecSuccess) { @@ -121,7 +121,7 @@ void Store::repairPath(const StorePath & path) Worker::Targets goals; goals.emplace_back(gf.makePathSubstitutionGoal(path, Repair)); return goals; - }); + }).wait(aio.waitScope).value(); auto & result = results.goals.begin()->second; if (result.exitCode != Goal::ecSuccess) { @@ -140,7 +140,7 @@ void Store::repairPath(const StorePath & path) bmRepair )); return goals; - }); + }).wait(aio.waitScope).value(); } else throw Error(results.failingExitStatus, "cannot repair path '%s'", printStorePath(path)); } diff --git a/src/libstore/build/worker.cc b/src/libstore/build/worker.cc index 1cb4a6090..2a764b193 100644 --- a/src/libstore/build/worker.cc +++ b/src/libstore/build/worker.cc @@ -229,8 +229,8 @@ try { co_return result::failure(std::current_exception()); } -Worker::Results Worker::run(std::function req) -{ +kj::Promise> Worker::run(std::function req) +try { auto topGoals = req(goalFactory()); assert(!running); @@ -252,7 +252,9 @@ Worker::Results Worker::run(std::function req) promise = promise.exclusiveJoin(boopGC(*localStore)); } - return promise.wait(aio.waitScope).value(); + co_return co_await promise; +} catch (...) { + co_return result::failure(std::current_exception()); } kj::Promise> Worker::runImpl(Targets topGoals) diff --git a/src/libstore/build/worker.hh b/src/libstore/build/worker.hh index dc5e0e878..369e58b41 100644 --- a/src/libstore/build/worker.hh +++ b/src/libstore/build/worker.hh @@ -278,7 +278,7 @@ public: /** * Loop until the specified top-level goals have finished. */ - Results run(std::function req); + kj::Promise> run(std::function req); /** * Check whether the given valid path exists and has the right @@ -289,14 +289,18 @@ public: void markContentsGood(const StorePath & path); template - friend Results - processGoals(Store & store, Store & evalStore, kj::AsyncIoContext & aio, MkGoals && mkGoals); + friend kj::Promise> processGoals( + Store & store, Store & evalStore, kj::AsyncIoContext & aio, MkGoals && mkGoals + ) noexcept; }; template -Worker::Results -processGoals(Store & store, Store & evalStore, kj::AsyncIoContext & aio, MkGoals && mkGoals) -{ - return Worker(store, evalStore, aio).run(std::forward(mkGoals)); +kj::Promise> processGoals( + Store & store, Store & evalStore, kj::AsyncIoContext & aio, MkGoals && mkGoals +) noexcept +try { + co_return co_await Worker(store, evalStore, aio).run(std::forward(mkGoals)); +} catch (...) { + co_return result::failure(std::current_exception()); } } -- cgit v1.2.3