text
stringlengths
0
2.2M
bool has_response_receiver(const mailbox_element& src) {
return src.sender || !src.stages.empty();
}
} // namespace
// -- constructors, destructors, and assignment operators ----------------------
response_promise::response_promise(local_actor* self, strong_actor_ptr source,
forwarding_stack stages, message_id mid) {
CAF_ASSERT(self != nullptr);
// Form an invalid request promise when initialized from a response ID, since
// we always drop messages in this case. Also don't create promises for
// anonymous messages since there's nowhere to send the message to anyway.
if (requires_response(mid)) {
state_ = make_counted<state>();
state_->weak_self = self->ctrl();
state_->source.swap(source);
state_->stages.swap(stages);
state_->id = mid;
}
}
response_promise::response_promise(local_actor* self, mailbox_element& src)
: response_promise(self, std::move(src.sender), std::move(src.stages),
src.mid) {
// nop
}
// -- properties ---------------------------------------------------------------
bool response_promise::async() const noexcept {
return id().is_async();
}
bool response_promise::pending() const noexcept {
return state_ != nullptr && state_->weak_self != nullptr;
}
strong_actor_ptr response_promise::source() const noexcept {
if (state_)
return state_->source;
else
return nullptr;
}
response_promise::forwarding_stack response_promise::stages() const {
if (state_)
return state_->stages;
else
return {};
}
strong_actor_ptr response_promise::next() const noexcept {
if (state_)
return state_->stages.empty() ? state_->source : state_->stages[0];
else
return nullptr;
}
message_id response_promise::id() const noexcept {
if (state_)
return state_->id;
else
return make_message_id();
}
// -- delivery -----------------------------------------------------------------
void response_promise::deliver(message msg) {
CAF_LOG_TRACE(CAF_ARG(msg));
if (pending()) {
state_->deliver_impl(std::move(msg));
state_.reset();
}
}
void response_promise::deliver(error x) {
CAF_LOG_TRACE(CAF_ARG(x));
if (pending()) {
state_->deliver_impl(make_message(std::move(x)));
state_.reset();
}
}
void response_promise::deliver() {
CAF_LOG_TRACE(CAF_ARG(""));
if (pending()) {
state_->deliver_impl(make_message());
state_.reset();
}
}
void response_promise::respond_to(local_actor* self, mailbox_element* request,
message& response) {
if (request && requires_response(*request)
&& has_response_receiver(*request)) {
state tmp;
tmp.weak_self = self->ctrl();