Commit e520075d authored by Dominik Charousset's avatar Dominik Charousset

Use self ptr to retrieve context in promise

parent 625ff651
......@@ -256,7 +256,7 @@ public:
auto& mid = ptr->mid;
if (mid.is_answered())
return {};
return {this->context(), this->ctrl(), *ptr};
return {this->ctrl(), *ptr};
}
/// Creates a `response_promise` to respond to a request later on.
......
......@@ -41,8 +41,9 @@ public:
/// Constructs an invalid response promise.
response_promise();
response_promise(execution_unit* ctx, strong_actor_ptr self,
mailbox_element& src);
response_promise(none_t);
response_promise(strong_actor_ptr self, mailbox_element& src);
response_promise(response_promise&&) = default;
response_promise(const response_promise&) = default;
......@@ -81,7 +82,7 @@ public:
dest->enqueue(make_mailbox_element(std::move(source_), mid,
std::move(stages_),
std::forward<Ts>(xs)...),
ctx_);
context());
}
return {};
}
......@@ -114,9 +115,10 @@ public:
}
private:
execution_unit* context();
response_promise deliver_impl(message msg);
execution_unit* ctx_;
strong_actor_ptr self_;
strong_actor_ptr source_;
forwarding_stack stages_;
......
......@@ -35,9 +35,8 @@ public:
/// Constructs an invalid response promise.
typed_response_promise() = default;
inline typed_response_promise(execution_unit* ctx, strong_actor_ptr self,
mailbox_element& src)
: promise_(ctx, std::move(self), src) {
inline typed_response_promise(strong_actor_ptr self, mailbox_element& src)
: promise_(std::move(self), src) {
// nop
}
......
......@@ -32,10 +32,8 @@ response_promise::response_promise()
// nop
}
response_promise::response_promise(execution_unit* ctx, strong_actor_ptr self,
mailbox_element& src)
: ctx_(ctx),
self_(std::move(self)),
response_promise::response_promise(strong_actor_ptr self, mailbox_element& src)
: self_(std::move(self)),
id_(src.mid) {
// form an invalid request promise when initialized from a
// response ID, since CAF always drops messages in this case
......@@ -54,18 +52,26 @@ bool response_promise::async() const {
return id_.is_async();
}
execution_unit* response_promise::context() {
return self_ == nullptr
? nullptr
: static_cast<local_actor*>(actor_cast<abstract_actor*>(self_))
->context();
}
response_promise response_promise::deliver_impl(message msg) {
if (!stages_.empty()) {
auto next = std::move(stages_.back());
stages_.pop_back();
next->enqueue(make_mailbox_element(std::move(source_), id_,
std::move(stages_), std::move(msg)),
ctx_);
context());
return *this;
}
if (source_) {
source_->enqueue(std::move(self_), id_.response_id(),
std::move(msg), ctx_);
std::move(msg), context());
source_.reset();
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