From: Samuel Just Date: Thu, 10 Jun 2021 00:34:21 +0000 (-0700) Subject: crimson/common/interruptible_future: add handle_interruption X-Git-Tag: v17.1.0~1567^2~19 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2f8bb018d2694ed6693011ddb2155cc1b46fef0f;p=ceph.git crimson/common/interruptible_future: add handle_interruption Signed-off-by: Samuel Just --- diff --git a/src/crimson/common/interruptible_future.h b/src/crimson/common/interruptible_future.h index 8cb516453e65..61d40d770471 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() {