diff --git a/core/future-util.hh b/core/future-util.hh index e84087e1bf..76b54f22bb 100644 --- a/core/future-util.hh +++ b/core/future-util.hh @@ -207,28 +207,11 @@ future<> do_until(StopCondition&& stop_cond, AsyncAction&& action) { template static inline future<> keep_doing(AsyncAction&& action) { - while (task_quota) { - auto f = action(); - - if (!f.available()) { - return f.then([action = std::forward(action)] () mutable { - return keep_doing(std::forward(action)); - }); - } - - if (f.failed()) { - return std::move(f); - } - - --task_quota; - } - - promise<> p; - auto f = p.get_future(); - schedule(make_task([action = std::forward(action), p = std::move(p)] () mutable { - keep_doing(std::forward(action)).forward_to(std::move(p)); - })); - return f; + return repeat([action = std::forward(action)] () mutable { + return action().then([] { + return stop_iteration::no; + }); + }); } /// Call a function for each item in a range, sequentially (iterator version).