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);
|
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");
|
debug("entered goal loop");
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
@ -313,12 +325,7 @@ std::vector<GoalPtr> Worker::run(std::function<Targets (GoalFactory &)> req)
|
||||||
Goals awake2 = std::move(awake);
|
Goals awake2 = std::move(awake);
|
||||||
for (auto & goal : awake2) {
|
for (auto & goal : awake2) {
|
||||||
checkInterrupt();
|
checkInterrupt();
|
||||||
auto result = goal->work();
|
childStarted(goal, goal->work());
|
||||||
if (result.poll(aio.waitScope)) {
|
|
||||||
handleWorkResult(goal, result.wait(aio.waitScope).value());
|
|
||||||
} else {
|
|
||||||
childStarted(goal, std::move(result));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (topGoals.empty()) break; // stuff may have been cancelled
|
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. */
|
/* Wait for input. */
|
||||||
if (!children.isEmpty())
|
if (!children.isEmpty())
|
||||||
waitForInput().wait(aio.waitScope).value();
|
(co_await waitForInput()).value();
|
||||||
else {
|
else {
|
||||||
assert(!awake.empty());
|
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 || awake.empty());
|
||||||
assert(!settings.keepGoing || children.isEmpty());
|
assert(!settings.keepGoing || children.isEmpty());
|
||||||
|
|
||||||
std::vector<GoalPtr> results;
|
co_return result::success();
|
||||||
for (auto & [i, _p] : _topGoals) {
|
} catch (...) {
|
||||||
results.push_back(i);
|
co_return result::failure(std::current_exception());
|
||||||
}
|
|
||||||
return results;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
kj::Promise<Result<void>> Worker::waitForInput()
|
kj::Promise<Result<void>> Worker::waitForInput()
|
||||||
|
|
|
@ -188,6 +188,8 @@ private:
|
||||||
statisticsOutdated = true;
|
statisticsOutdated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kj::Promise<Result<void>> runImpl();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
const Activity act;
|
const Activity act;
|
||||||
|
|
Loading…
Reference in a new issue