From e5e7348f7656b35ed5d7230fe41f047e04bb30d0 Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Sat, 20 Jun 2015 19:03:21 +0200 Subject: [PATCH] core: Reimplement keep_doing() using repeat() --- core/future-util.hh | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) 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).