Permalink
Browse files

added `quit_actor` function

  • Loading branch information...
1 parent 6d7bb47 commit c2f9b16760570cc6f0c5d50660d4edbc9865ec34 @Neverlord Neverlord committed Feb 18, 2013
View
@@ -989,6 +989,15 @@ actor_ptr remote_actor(network::io_stream_ptr_pair connection);
*/
void shutdown(); // note: implemented in singleton_manager.cpp
+/**
+ * @brief Causes @p whom to quit with @p reason.
+ * @note Does nothing if <tt>reason == exit_reason::normal</tt>.
+ */
+inline void quit_actor(const actor_ptr& whom, std::uint32_t reason) {
+ CPPA_REQUIRE(reason != exit_reason::normal);
+ send(whom, atom("EXIT"), reason);
+}
+
struct actor_ostream {
typedef const actor_ostream& (*fun_type)(const actor_ostream&);
@@ -156,7 +156,7 @@ int main(int argc, char** argv) {
}
);
// force actor to quit
- send(client_actor, atom("EXIT"), exit_reason::user_defined);
+ quit_actor(client_actor, exit_reason::user_defined);
await_all_others_done();
shutdown();
return 0;
@@ -21,7 +21,7 @@ behavior ping_behavior(size_t num_pings) {
CPPA_LOGF_ERROR_IF(!self->last_sender(), "last_sender() == nullptr");
//cout << to_string(self->last_dequeued()) << endl;
if (++s_pongs >= num_pings) {
- reply(atom("EXIT"), exit_reason::user_defined);
+ quit_actor(self->last_sender(), exit_reason::user_defined);
self->quit();
}
else reply(atom("ping"), value);
@@ -216,7 +216,7 @@ string behavior_test(actor_ptr et) {
throw runtime_error(testee_name + " does not reply");
}
);
- send(et, atom("EXIT"), exit_reason::user_defined);
+ quit_actor(et, exit_reason::user_defined);
await_all_others_done();
return result;
}
@@ -320,7 +320,7 @@ int main() {
CPPA_PRINT("test mirror");
send(mirror, "hello mirror");
receive(on("hello mirror") >> []() { });
- send(mirror, atom("EXIT"), exit_reason::user_defined);
+ quit_actor(mirror, exit_reason::user_defined);
await_all_others_done();
CPPA_CHECKPOINT();
@@ -419,7 +419,7 @@ int main() {
CPPA_CHECK(values == expected);
}
// terminate st
- send(st, atom("EXIT"), exit_reason::user_defined);
+ quit_actor(st, exit_reason::user_defined);
await_all_others_done();
CPPA_CHECKPOINT();
@@ -615,9 +615,8 @@ int main() {
CPPA_CHECK_EQUAL(name, "bob");
}
);
- auto kill_msg = make_any_tuple(atom("EXIT"), exit_reason::user_defined);
- a1 << kill_msg;
- a2 << kill_msg;
+ quit_actor(a1, exit_reason::user_defined);
+ quit_actor(a2, exit_reason::user_defined);
await_all_others_done();
factory::event_based([](int* i) {
@@ -646,7 +645,7 @@ int main() {
}
);
});
- send(twenty_thousand, atom("EXIT"), exit_reason::user_defined);
+ quit_actor(twenty_thousand, exit_reason::user_defined);
await_all_others_done();
self->trap_exit(true);
auto ping_actor = spawn_monitor(ping, 10);
@@ -657,12 +656,12 @@ int main() {
delayed_send(self, chrono::seconds(1), atom("FooBar"));
// wait for DOWN and EXIT messages of pong
receive_for(i, 4) (
- on<atom("EXIT"), uint32_t>() >> [&](uint32_t reason) {
+ on(atom("EXIT"), arg_match) >> [&](uint32_t reason) {
CPPA_CHECK_EQUAL(exit_reason::user_defined, reason);
CPPA_CHECK(self->last_sender() == pong_actor);
flags |= 0x01;
},
- on<atom("DOWN"), uint32_t>() >> [&](uint32_t reason) {
+ on(atom("DOWN"), arg_match) >> [&](uint32_t reason) {
auto who = self->last_sender();
if (who == pong_actor) {
flags |= 0x02;
@@ -127,7 +127,7 @@ int main() {
);
self->exec_behavior_stack();
CPPA_CHECK_EQUAL(continuation_called, true);
- send(mirror, atom("EXIT"), exit_reason::user_defined);
+ quit_actor(mirror, exit_reason::user_defined);
await_all_others_done();
CPPA_CHECKPOINT();
auto await_success_message = [&] {
@@ -180,7 +180,10 @@ int main() {
sync_send(c, atom("gogo")).then(CPPA_CHECKPOINT_CB())
.continue_with(CPPA_CHECKPOINT_CB());
self->exec_behavior_stack();
- send(c, atom("EXIT"), exit_reason::user_defined);
+ quit_actor(c, exit_reason::user_defined);
+ await_all_others_done();
+ CPPA_CHECKPOINT();
+
await_all_others_done();
CPPA_CHECKPOINT();
shutdown();

0 comments on commit c2f9b16

Please sign in to comment.