Commit e3267858 authored by Dominik Charousset's avatar Dominik Charousset

Support expected<T> in response promise

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