text
stringlengths 0
2.2M
|
---|
tmp.source.swap(request->sender);
|
tmp.stages.swap(request->stages);
|
tmp.id = request->mid;
|
tmp.deliver_impl(std::move(response));
|
request->mid.mark_as_answered();
|
}
|
}
|
void response_promise::respond_to(local_actor* self, mailbox_element* request,
|
error& response) {
|
if (request && requires_response(*request)
|
&& has_response_receiver(*request)) {
|
state tmp;
|
tmp.weak_self = self->ctrl();
|
tmp.source.swap(request->sender);
|
tmp.stages.swap(request->stages);
|
tmp.id = request->mid;
|
tmp.deliver_impl(make_message(std::move(response)));
|
request->mid.mark_as_answered();
|
}
|
}
|
// -- state --------------------------------------------------------------------
|
response_promise::state::~state() {
|
// Note: the state may get destroyed outside of the actor. For example, when
|
// storing the promise in a run-later continuation. Hence, we can't call
|
// deliver_impl here since it calls self->context().
|
if (weak_self && source) {
|
CAF_LOG_DEBUG("broken promise!");
|
auto element = make_mailbox_element(weak_self.lock(), id.response_id(),
|
no_stages,
|
make_error(sec::broken_promise));
|
source->enqueue(std::move(element), nullptr);
|
}
|
}
|
void response_promise::state::cancel() {
|
weak_self = nullptr;
|
}
|
void response_promise::state::deliver_impl(message msg) {
|
CAF_LOG_TRACE(CAF_ARG(msg));
|
// Even though we are holding a weak pointer, we can access the pointer
|
// without any additional check here because only the actor itself is allowed
|
// to call this function.
|
auto self = static_cast<local_actor*>(weak_self.get()->get());
|
if (msg.empty() && id.is_async()) {
|
CAF_LOG_DEBUG("drop response: empty response to asynchronous input");
|
} else if (!stages.empty()) {
|
auto next = std::move(stages.back());
|
stages.pop_back();
|
detail::profiled_send(self, std::move(source), next, id, std::move(stages),
|
self->context(), std::move(msg));
|
} else if (source != nullptr) {
|
detail::profiled_send(self, self->ctrl(), source, id.response_id(),
|
forwarding_stack{}, self->context(), std::move(msg));
|
}
|
cancel();
|
}
|
void response_promise::state::delegate_impl(abstract_actor* receiver,
|
message msg) {
|
CAF_LOG_TRACE(CAF_ARG(msg));
|
if (receiver != nullptr) {
|
auto self = static_cast<local_actor*>(weak_self.get()->get());
|
detail::profiled_send(self, std::move(source), receiver, id,
|
std::move(stages), self->context(), std::move(msg));
|
} else {
|
CAF_LOG_DEBUG("drop response: invalid delegation target");
|
}
|
cancel();
|
}
|
} // namespace caf
|
// This file is part of CAF, the C++ Actor Framework. See the file LICENSE in
|
// the main distribution directory for license terms and copyright or visit
|
// https://github.com/actor-framework/actor-framework/blob/master/LICENSE.
|
#include "caf/config_option.hpp"
|
#include <algorithm>
|
#include <limits>
|
#include <numeric>
|
#include "caf/config.hpp"
|
#include "caf/config_value.hpp"
|
#include "caf/error.hpp"
|
#include "caf/expected.hpp"
|
#include "caf/optional.hpp"
|
using std::move;
|
using std::string;
|
namespace caf {
|
// -- constructors, destructors, and assignment operators ----------------------
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.