Unverified Commit b3a37559 authored by Dominik Charousset's avatar Dominik Charousset Committed by GitHub

Merge pull request #1190

Align typed_response_promise with response_promise
parents 548f9392 d00891e1
......@@ -73,6 +73,8 @@ public:
make_message(std::forward<T>(x), std::forward<Ts>(xs)...));
}
/// Satisfies the promise by sending either an error or a non-error response
/// message.
template <class T>
void deliver(expected<T> x) {
if (x)
......@@ -92,8 +94,7 @@ public:
typename std::decay<Ts>::type>::type...>;
static_assert(response_type_unbox<signatures_of_t<Handle>, token>::valid,
"receiver does not accept given message");
// TODO: use `if constexpr` when switching to C++17
if (P == message_priority::high)
if constexpr (P == message_priority::high)
id_ = id_.with_high_priority();
if constexpr (std::is_same<detail::type_list<message>,
detail::type_list<std::decay_t<Ts>...>>::value)
......
......@@ -30,9 +30,21 @@ namespace caf {
template <class... Ts>
class typed_response_promise {
public:
using forwarding_stack = response_promise::forwarding_stack;
/// Constructs an invalid response promise.
typed_response_promise() = default;
typed_response_promise(none_t x) : promise_(x) {
// nop
}
typed_response_promise(strong_actor_ptr self, strong_actor_ptr source,
forwarding_stack stages, message_id id)
: promise_(std::move(self), std::move(source), std::move(stages), id) {
// nop
}
typed_response_promise(strong_actor_ptr self, mailbox_element& src)
: promise_(std::move(self), src) {
// nop
......@@ -44,6 +56,7 @@ public:
typed_response_promise& operator=(const typed_response_promise&) = default;
/// Implicitly convertible to untyped response promise.
[[deprecated("Use the typed_response_promise directly.")]]
operator response_promise&() {
return promise_;
}
......@@ -63,6 +76,16 @@ public:
return *this;
}
/// Satisfies the promise by sending either an error or a non-error response
/// message.
template <class T>
void 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... Us>
typed_response_promise delegate(const Handle& dest, Us&&... xs) {
......@@ -77,11 +100,37 @@ public:
return *this;
}
/// Returns whether this response promise replies to an asynchronous message.
bool async() const {
return promise_.async();
}
/// Queries whether this promise is a valid promise that is not satisfied yet.
bool pending() const {
return promise_.pending();
}
/// Returns the source of the corresponding request.
const strong_actor_ptr& source() const {
return promise_.source();
}
/// Returns the remaining stages for the corresponding request.
const forwarding_stack& stages() const {
return promise_.stages();
}
/// Returns the actor that will receive the response, i.e.,
/// `stages().front()` if `!stages().empty()` or `source()` otherwise.
strong_actor_ptr next() const {
return promise_.next();
}
/// Returns the message ID of the corresponding request.
message_id id() const {
return promise_.id();
}
private:
response_promise promise_;
};
......
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