【发布时间】:2019-01-03 15:56:50
【问题描述】:
当我通过调用 put(atom_value, actor ),我的进度不会自动终止,直到我杀死它才会停止。
但是,当我显式添加 erase() 时,它将退出。
其实正如CAF手册第8节所说:
Actor 终止时会自动移除。
这就是我想要的。所以我想知道这是否是一个错误。
- 我在 MacOS 10.13.4 上运行,
- 编译器是 Apple LLVM 版本 9.1.0 (clang-902.0.39.2)。
- CAF 版本:0.15.7
为了重现我的结果,请运行以下 c++ 代码:
#include <string>
#include <iostream>
#include "caf/all.hpp"
#include "caf/io/all.hpp"
using std::endl;
using std::string;
using namespace caf;
atom_value world_atom = atom("world_act");
atom_value hello_atom = atom("hello_act");
behavior world(event_based_actor *self) {
return behavior {
[=](const string &what) {
aout(self) << "Message: " << what << endl;
return std::string{"World"};
}
};
}
void hello(event_based_actor* self) {
string out_msg{"Hello "};
auto tmp = self->home_system().registry().get(world_atom);
auto buddy = actor_cast<actor>(tmp);
self->request(actor_cast<actor>(tmp), std::chrono::seconds(2), out_msg).then(
[=] (const string& what) {
aout(self) << "Message: " << what << endl;
});
}
int main() {
actor_system_config cfg;
actor_system system{cfg};
auto world_actor = system.spawn(world);
system.registry().put(world_atom, world_actor);
auto hello_actor = system.spawn(hello);
system.registry().put(hello_atom, hello_actor);
std::cout << "current running: " << system.registry().running() << endl;
/* Uncomment the following three lines if you want to stop automatically */
// getchar();
// system.registry().erase(hello_atom);
// system.registry().erase(world_atom);
return 0;
}
【问题讨论】:
标签: c++ actor c++-actor-framework