diff --git a/core/async-action.hh b/core/async-action.hh index 02835278d9..3af904a152 100644 --- a/core/async-action.hh +++ b/core/async-action.hh @@ -45,17 +45,20 @@ future<> do_until(StopCondition&& stop_cond, AsyncAction&& action) { return f; } -// Invoke given action undefinitely. Next invocation starts when previous completes or fails. +// Invoke given action until it fails. template static inline -void keep_doing(AsyncAction&& action) { +future<> keep_doing(AsyncAction&& action) { while (true) { auto f = action(); if (!f.available()) { - f.then([action = std::forward(action)] () mutable { - keep_doing(std::forward(action)); + return f.then([action = std::forward(action)] () mutable { + return keep_doing(std::forward(action)); }); - return; + } + + if (f.failed()) { + return std::move(f); } } }