本文整理汇总了C++中message_id::is_answered方法的典型用法代码示例。如果您正苦于以下问题:C++ message_id::is_answered方法的具体用法?C++ message_id::is_answered怎么用?C++ message_id::is_answered使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类message_id
的用法示例。
在下文中一共展示了message_id::is_answered方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: move
optional<message> invoke_fun(Actor* self, message& msg, message_id& mid,
Fun& fun,
MaybeResponseHdl hdl = MaybeResponseHdl{}) {
# ifdef CAF_LOG_LEVEL
auto msg_str = to_string(msg);
# endif
CAF_LOG_TRACE(CAF_MARG(mid, integer_value) << ", msg = " << msg_str);
auto res = fun(msg); // might change mid
CAF_LOG_DEBUG_IF(res, "actor did consume message: " << msg_str);
CAF_LOG_DEBUG_IF(!res, "actor did ignore message: " << msg_str);
if (!res) {
return none;
}
if (res->empty()) {
// make sure synchronous requests
// always receive a response
if (mid.is_request() && !mid.is_answered()) {
CAF_LOG_WARNING("actor with ID " << self->id()
<< " did not reply to a synchronous request message");
auto fhdl = fetch_response_promise(self, hdl);
if (fhdl) {
fhdl.deliver(make_message(unit));
}
}
} else {
CAF_LOGF_DEBUG("res = " << to_string(*res));
if (res->template has_types<atom_value, uint64_t>()
&& res->template get_as<atom_value>(0) == atom("MESSAGE_ID")) {
CAF_LOG_DEBUG("message handler returned a message id wrapper");
auto id = res->template get_as<uint64_t>(1);
auto msg_id = message_id::from_integer_value(id);
auto ref_opt = self->sync_handler(msg_id);
// calls self->response_promise() if hdl is a dummy
// argument, forwards hdl otherwise to reply to the
// original request message
auto fhdl = fetch_response_promise(self, hdl);
if (ref_opt) {
behavior cpy = *ref_opt;
*ref_opt =
cpy.add_continuation([=](message & intermediate)
->optional<message> {
if (!intermediate.empty()) {
// do no use lamba expresion type to
// avoid recursive template instantiaton
behavior::continuation_fun f2 = [=](
message & m)->optional<message> {
return std::move(m);
};
auto mutable_mid = mid;
// recursively call invoke_fun on the
// result to correctly handle stuff like
// sync_send(...).then(...).then(...)...
return this->invoke_fun(self, intermediate,
mutable_mid, f2, fhdl);
}
return none;
});
}
// reset res to prevent "outer" invoke_fun
// from handling the result again
res->reset();
} else {
// respond by using the result of 'fun'
CAF_LOG_DEBUG("respond via response_promise");
auto fhdl = fetch_response_promise(self, hdl);
if (fhdl) {
fhdl.deliver(std::move(*res));
// inform caller about success
return message{};
}
}
}
return res;
}