forked from lix-project/lix
libstore: turn Worker::run() main loop into a promise
Change-Id: Ib112ea9a3e67d5cb3d7d0ded30bbd25c96262470
This commit is contained in:
parent
d31310bf59
commit
b0c7c1ec66
|
@ -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()
|
||||
|
|
|
@ -188,6 +188,8 @@ private:
|
|||
statisticsOutdated = true;
|
||||
}
|
||||
|
||||
kj::Promise<Result<void>> runImpl();
|
||||
|
||||
public:
|
||||
|
||||
const Activity act;
|
||||
|
|
Loading…
Reference in a new issue