core: Reimplement keep_doing() using repeat()

This commit is contained in:
Tomasz Grabiec
2015-06-20 19:03:21 +02:00
parent 61992f84c5
commit e5e7348f76

View File

@@ -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).