aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/build/worker.cc
diff options
context:
space:
mode:
authoreldritch horrors <pennae@lix.systems>2024-09-30 01:31:29 +0200
committereldritch horrors <pennae@lix.systems>2024-10-01 11:36:45 +0000
commitb0c7c1ec664415d451dcd56d2982b369c0c33892 (patch)
tree43baaf474c215e540e93863237008ee2859d10a1 /src/libstore/build/worker.cc
parentd31310bf59a6a51945eb2d671585815b93f4df00 (diff)
libstore: turn Worker::run() main loop into a promise
Change-Id: Ib112ea9a3e67d5cb3d7d0ded30bbd25c96262470
Diffstat (limited to 'src/libstore/build/worker.cc')
-rw-r--r--src/libstore/build/worker.cc29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/libstore/build/worker.cc b/src/libstore/build/worker.cc
index 7dd75f34a..8ab7fcc86 100644
--- a/src/libstore/build/worker.cc
+++ b/src/libstore/build/worker.cc
@@ -297,6 +297,18 @@ std::vector<GoalPtr> Worker::run(std::function<Targets (GoalFactory &)> req)
topGoals.insert(goal);
}
+ auto promise = runImpl();
+ promise.wait(aio.waitScope).value();
+
+ std::vector<GoalPtr> results;
+ for (auto & [i, _p] : _topGoals) {
+ results.push_back(i);
+ }
+ return results;
+}
+
+kj::Promise<Result<void>> Worker::runImpl()
+try {
debug("entered goal loop");
while (1) {
@@ -313,12 +325,7 @@ std::vector<GoalPtr> Worker::run(std::function<Targets (GoalFactory &)> req)
Goals awake2 = std::move(awake);
for (auto & goal : awake2) {
checkInterrupt();
- auto result = goal->work();
- if (result.poll(aio.waitScope)) {
- handleWorkResult(goal, result.wait(aio.waitScope).value());
- } else {
- childStarted(goal, std::move(result));
- }
+ childStarted(goal, goal->work());
if (topGoals.empty()) break; // stuff may have been cancelled
}
@@ -328,7 +335,7 @@ std::vector<GoalPtr> Worker::run(std::function<Targets (GoalFactory &)> req)
/* Wait for input. */
if (!children.isEmpty())
- waitForInput().wait(aio.waitScope).value();
+ (co_await waitForInput()).value();
else {
assert(!awake.empty());
}
@@ -344,11 +351,9 @@ std::vector<GoalPtr> Worker::run(std::function<Targets (GoalFactory &)> req)
assert(!settings.keepGoing || awake.empty());
assert(!settings.keepGoing || children.isEmpty());
- std::vector<GoalPtr> results;
- for (auto & [i, _p] : _topGoals) {
- results.push_back(i);
- }
- return results;
+ co_return result::success();
+} catch (...) {
+ co_return result::failure(std::current_exception());
}
kj::Promise<Result<void>> Worker::waitForInput()