Merge pull request #43247 from rzarzynski/wip-crimson-ertr-safe_then_unpack

crimson/common: add safe_then_unpack() to errorated futures

Reviewed-by: Samuel Just <sjust@redhat.com>
Reviewed-by: Chunmei Liu <chunmei.liu@intel.com>
This commit is contained in:
Samuel Just 2021-09-21 17:12:58 -07:00 committed by GitHub
commit 86b9f03094
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -8,6 +8,7 @@
#include <seastar/core/future-util.hh>
#include "crimson/common/utility.h"
#include "include/ceph_assert.h"
namespace crimson::interruptible {
@ -667,6 +668,19 @@ private:
errorator_type::pass_further{});
}
template <class ValueFunc,
class... ErrorFuncs>
auto safe_then_unpack(ValueFunc&& value_func,
ErrorFuncs&&... error_funcs) {
return safe_then(
[value_func=std::move(value_func)] (ValueT&& tuple) mutable {
assert_moveable(value_func);
return std::apply(std::move(value_func), std::move(tuple));
},
std::forward<ErrorFuncs>(error_funcs)...
);
}
template <class Func>
void then(Func&&) = delete;

View File

@ -5,12 +5,16 @@
#include <type_traits>
namespace _impl {
template <class T> struct always_false : std::false_type {};
};
template <class T>
void assert_moveable(T& t) {
// It's fine
}
template <class T>
void assert_moveable(const T& t) {
static_assert(always_false<T>::value, "unable to move-out from T");
static_assert(_impl::always_false<T>::value, "unable to move-out from T");
}