Commit eaf70871 authored by Dominik Charousset's avatar Dominik Charousset

Generalize response promise

parent f9e52814
...@@ -256,7 +256,7 @@ public: ...@@ -256,7 +256,7 @@ public:
auto& mid = ptr->mid; auto& mid = ptr->mid;
if (mid.is_answered()) if (mid.is_answered())
return {}; return {};
return {this, *ptr}; return {this->context(), this->ctrl(), *ptr};
} }
/// Creates a `response_promise` to respond to a request later on. /// Creates a `response_promise` to respond to a request later on.
......
...@@ -36,7 +36,9 @@ class response_promise { ...@@ -36,7 +36,9 @@ class response_promise {
public: public:
/// Constructs an invalid response promise. /// Constructs an invalid response promise.
response_promise(); response_promise();
response_promise(local_actor* self, mailbox_element& src);
response_promise(execution_unit* ctx, strong_actor_ptr self,
mailbox_element& src);
response_promise(response_promise&&) = default; response_promise(response_promise&&) = default;
response_promise(const response_promise&) = default; response_promise(const response_promise&) = default;
...@@ -65,20 +67,13 @@ public: ...@@ -65,20 +67,13 @@ public:
return !stages_.empty() || source_; return !stages_.empty() || source_;
} }
/// @cond PRIVATE
inline local_actor* self() {
return self_;
}
/// @endcond
private: private:
using forwarding_stack = std::vector<strong_actor_ptr>; using forwarding_stack = std::vector<strong_actor_ptr>;
response_promise deliver_impl(message response_message); response_promise deliver_impl(message response_message);
local_actor* self_; execution_unit* ctx_;
strong_actor_ptr self_;
strong_actor_ptr source_; strong_actor_ptr source_;
forwarding_stack stages_; forwarding_stack stages_;
message_id id_; message_id id_;
......
...@@ -35,8 +35,9 @@ public: ...@@ -35,8 +35,9 @@ public:
/// Constructs an invalid response promise. /// Constructs an invalid response promise.
typed_response_promise() = default; typed_response_promise() = default;
inline typed_response_promise(local_actor* self, mailbox_element& src) inline typed_response_promise(execution_unit* ctx, strong_actor_ptr self,
: promise_(self, src) { mailbox_element& src)
: promise_(ctx, std::move(self), src) {
// nop // nop
} }
......
...@@ -30,8 +30,10 @@ response_promise::response_promise() ...@@ -30,8 +30,10 @@ response_promise::response_promise()
// nop // nop
} }
response_promise::response_promise(local_actor* ptr, mailbox_element& src) response_promise::response_promise(execution_unit* ctx, strong_actor_ptr self,
: self_(ptr), mailbox_element& src)
: ctx_(ctx),
self_(std::move(self)),
id_(src.mid) { id_(src.mid) {
// form an invalid request promise when initialized from a // form an invalid request promise when initialized from a
// response ID, since CAF always drops messages in this case // response ID, since CAF always drops messages in this case
...@@ -55,13 +57,13 @@ response_promise response_promise::deliver_impl(message msg) { ...@@ -55,13 +57,13 @@ response_promise response_promise::deliver_impl(message msg) {
auto next = std::move(stages_.back()); auto next = std::move(stages_.back());
stages_.pop_back(); stages_.pop_back();
next->enqueue(make_mailbox_element(std::move(source_), id_, next->enqueue(make_mailbox_element(std::move(source_), id_,
std::move(stages_), std::move(msg)), std::move(stages_), std::move(msg)),
self_->context()); ctx_);
return *this; return *this;
} }
if (source_) { if (source_) {
source_->enqueue(self_->ctrl(), id_.response_id(), source_->enqueue(std::move(self_), id_.response_id(),
std::move(msg), self_->context()); std::move(msg), ctx_);
source_.reset(); source_.reset();
return *this; return *this;
} }
......
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