From 2f8bb018d2694ed6693011ddb2155cc1b46fef0f Mon Sep 17 00:00:00 2001 From: Samuel Just Date: Wed, 9 Jun 2021 17:34:21 -0700 Subject: [PATCH] crimson/common/interruptible_future: add handle_interruption Signed-off-by: Samuel Just --- src/crimson/common/interruptible_future.h | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/crimson/common/interruptible_future.h b/src/crimson/common/interruptible_future.h index 8cb516453e6..61d40d77047 100644 --- a/src/crimson/common/interruptible_future.h +++ b/src/crimson/common/interruptible_future.h @@ -798,6 +798,35 @@ public: auto fut = core_type::finally(std::forward(func)); return (interrupt_futurize_t)(std::move(fut)); } + + template + [[gnu::always_inline]] + auto handle_interruption(Func&& func) { + // see errorator.h safe_then definition + using func_result_t = + typename std::invoke_result::type; + using func_ertr_t = + typename core_type::template get_errorator_t; + using this_ertr_t = typename core_type::errorator_type; + using ret_ertr_t = typename this_ertr_t::template extend_ertr; + using futurator_t = typename ret_ertr_t::template futurize; + return core_type::then_wrapped( + [func=std::move(func), + interrupt_condition=interrupt_cond](auto&& fut) mutable + -> typename futurator_t::type { + if (fut.failed()) { + std::exception_ptr ex = fut.get_exception(); + if (interrupt_condition->is_interruption(ex)) { + return futurator_t::invoke(std::move(func), std::move(ex)); + } else { + return futurator_t::make_exception_future(std::move(ex)); + } + } else { + return std::move(fut); + } + }); + } + private: ErroratedFuture<::crimson::errorated_future_marker> to_future() { -- 2.39.5