Commit e3267858 authored by Dominik Charousset's avatar Dominik Charousset

Support expected<T> in response promise

parent 014b1fb3
...@@ -54,20 +54,27 @@ public: ...@@ -54,20 +54,27 @@ public:
/// Satisfies the promise by sending a non-error response message. /// Satisfies the promise by sending a non-error response message.
template <class T, class... Ts> template <class T, class... Ts>
typename std::enable_if< detail::enable_if_t<
(sizeof...(Ts) > 0) || !std::is_convertible<T, error>::value, ((sizeof...(Ts) > 0) || !std::is_convertible<T, error>::value)
response_promise && !detail::is_expected<detail::decay_t<T>>::value,
>::type response_promise>
deliver(T&&x, Ts&&... xs) { deliver(T&& x, Ts&&... xs) {
static_assert(!detail::is_specialization<result, T>::value using ts = detail::type_list<detail::decay_t<T>, detail::decay_t<Ts>...>;
&& !detail::disjunction< static_assert(!detail::tl_exists<ts, detail::is_result>::value,
detail::is_specialization<result, Ts>::value... "it is not possible to deliver objects of type result<T>");
>::value, static_assert(!detail::tl_exists<ts, detail::is_expected>::value,
"it is not possible to deliver objects of type result<...>"); "mixing expected<T> with regular values is not supported");
return deliver_impl(make_message(std::forward<T>(x), return deliver_impl(make_message(std::forward<T>(x),
std::forward<Ts>(xs)...)); std::forward<Ts>(xs)...));
} }
template <class T>
response_promise deliver(expected<T> x) {
if (x)
return deliver(std::move(*x));
return deliver(std::move(x.error()));
}
/// Satisfies the promise by delegating to another actor. /// Satisfies the promise by delegating to another actor.
template <message_priority P = message_priority::normal, template <message_priority P = message_priority::normal,
class Handle = actor, class... Ts> class Handle = actor, class... Ts>
......
...@@ -90,10 +90,7 @@ VARARGS_TESTEE(file_reader, size_t buf_size) { ...@@ -90,10 +90,7 @@ VARARGS_TESTEE(file_reader, size_t buf_size) {
is_done(self), is_done(self),
[=](expected<int> x) mutable { [=](expected<int> x) mutable {
CAF_MESSAGE(self->name() << " received the result"); CAF_MESSAGE(self->name() << " received the result");
if (x) rp.deliver(std::move(x));
rp.deliver(*x);
else
rp.deliver(std::move(x.error()));
} }
); );
return rp; return rp;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment