]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
crimson/common/errorator.h: add finally method for resource release
authorSamuel Just <sjust@redhat.com>
Fri, 22 Nov 2019 01:52:00 +0000 (01:52 +0000)
committerSamuel Just <sjust@redhat.com>
Tue, 3 Dec 2019 05:35:36 +0000 (21:35 -0800)
This way we can add things like resource handlers which are otherwise
transparent to passing values and errors.

Signed-off-by: Samuel Just <sjust@redhat.com>
src/crimson/common/errorator.h

index 28aa729fe88671c643a0a28c7fb9bcd8fe28d67e..dc0ec2e61c8b4d17b9a505606219d129d50978df 100644 (file)
@@ -518,6 +518,24 @@ private:
         });
     }
 
+    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 [[gnu::always_inline]] noexcept {
+         return futurator_t::apply(std::forward<FuncT>(func)).safe_then(
+           [future = std::forward<decltype(future)>(future)]() mutable {
+             return std::move(future);
+           });
+       });
+    }
+
     // taking ErrorFuncOne and ErrorFuncTwo separately from ErrorFuncTail
     // to avoid SFINAE
     template <class ValueFunc,