]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/common: discard failure of finally() block
authorKefu Chai <kchai@redhat.com>
Sat, 19 Sep 2020 02:32:45 +0000 (10:32 +0800)
committerKefu Chai <kchai@redhat.com>
Sat, 19 Sep 2020 04:40:50 +0000 (12:40 +0800)
instead of assuming that the function passed to finally() returns an
erroratorized future, in this change:

* s/safe_then/then_wrapped/ to handle the exception thrown by
  the finally function.
* specialize for the case where the finally function does not return
  a future, and just call it. note, in seastar's implementation of
  finally, `finally_body` is used for specializing these two cases.
* rename "future" to "result", for better readability.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/crimson/common/errorator.h

index 16335380192c94e470fd13abd4c47d1b7f2e4640..ea0ffea4d49151e82f92d963594b869c3a80f770 100644 (file)
@@ -592,23 +592,26 @@ private:
       return seastar::future<ValuesT...>::get0();
     }
 
-
     template <class FuncT>
     auto finally(FuncT &&func) {
-      using func_result_t = std::invoke_result_t<FuncT>;
-      using func_errorator_t = get_errorator_t<func_result_t>;
-      using return_errorator_t = func_errorator_t;
-      using futurator_t =
-        typename return_errorator_t::template futurize<func_result_t>;
-
       return this->then_wrapped(
-       [ func = std::forward<FuncT>(func)
-       ] (auto&& future) mutable noexcept {
-         return futurator_t::invoke(std::forward<FuncT>(func)).safe_then(
-           [future = std::forward<decltype(future)>(future)]() mutable {
-             return std::move(future);
-           });
-       });
+        [func = std::forward<FuncT>(func)](auto &&result) mutable noexcept {
+        if constexpr (seastar::is_future<std::invoke_result_t<FuncT>>::value) {
+          return ::seastar::futurize_invoke(std::forward<FuncT>(func)).then_wrapped(
+            [result = std::move(result)](auto&& f_res) mutable {
+            // TODO: f_res.failed()
+            f_res.discard_result();
+            return std::move(result);
+          });
+        } else {
+          try {
+            func();
+          } catch (...) {
+            // TODO: rethrow
+          }
+          return std::move(result);
+        }
+      });
     }
 
     // taking ErrorFuncOne and ErrorFuncTwo separately from ErrorFuncTail