mirror of
https://github.com/scylladb/scylladb.git
synced 2026-06-08 16:03:20 +00:00
core: Reimplement keep_doing() using repeat()
This commit is contained in:
@@ -207,28 +207,11 @@ future<> do_until(StopCondition&& stop_cond, AsyncAction&& action) {
|
||||
template<typename AsyncAction>
|
||||
static inline
|
||||
future<> keep_doing(AsyncAction&& action) {
|
||||
while (task_quota) {
|
||||
auto f = action();
|
||||
|
||||
if (!f.available()) {
|
||||
return f.then([action = std::forward<AsyncAction>(action)] () mutable {
|
||||
return keep_doing(std::forward<AsyncAction>(action));
|
||||
});
|
||||
}
|
||||
|
||||
if (f.failed()) {
|
||||
return std::move(f);
|
||||
}
|
||||
|
||||
--task_quota;
|
||||
}
|
||||
|
||||
promise<> p;
|
||||
auto f = p.get_future();
|
||||
schedule(make_task([action = std::forward<AsyncAction>(action), p = std::move(p)] () mutable {
|
||||
keep_doing(std::forward<AsyncAction>(action)).forward_to(std::move(p));
|
||||
}));
|
||||
return f;
|
||||
return repeat([action = std::forward<AsyncAction>(action)] () mutable {
|
||||
return action().then([] {
|
||||
return stop_iteration::no;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// Call a function for each item in a range, sequentially (iterator version).
|
||||
|
||||
Reference in New Issue
Block a user