From 454ee88bb6da896e667c5b0f87fbc45c9e2244fa Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Tue, 14 Oct 2014 13:49:21 +0200 Subject: [PATCH] core: make keep_doing() propagate failure --- core/async-action.hh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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); } } }