Commit 98cfdbfa authored by Dominik Charousset's avatar Dominik Charousset

Run actions in scheduled actors

parent 909ad46a
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "caf/actor_system_config.hpp" #include "caf/actor_system_config.hpp"
#include "caf/config.hpp" #include "caf/config.hpp"
#include "caf/defaults.hpp" #include "caf/defaults.hpp"
#include "caf/detail/action.hpp"
#include "caf/detail/default_invoke_result_visitor.hpp" #include "caf/detail/default_invoke_result_visitor.hpp"
#include "caf/detail/meta_object.hpp" #include "caf/detail/meta_object.hpp"
#include "caf/detail/private_thread.hpp" #include "caf/detail/private_thread.hpp"
...@@ -666,6 +667,13 @@ scheduled_actor::categorize(mailbox_element& x) { ...@@ -666,6 +667,13 @@ scheduled_actor::categorize(mailbox_element& x) {
call_handler(down_handler_, this, dm); call_handler(down_handler_, this, dm);
return message_category::internal; return message_category::internal;
} }
if (auto view = make_typed_message_view<detail::action>(content)) {
if (auto ptr = get<0>(view).ptr()) {
CAF_LOG_DEBUG("run action");
ptr->run();
}
return message_category::internal;
}
if (auto view = make_typed_message_view<node_down_msg>(content)) { if (auto view = make_typed_message_view<node_down_msg>(content)) {
auto& dm = get<0>(view); auto& dm = get<0>(view);
call_handler(node_down_handler_, this, dm); call_handler(node_down_handler_, this, dm);
......
...@@ -10,6 +10,14 @@ ...@@ -10,6 +10,14 @@
using namespace caf; using namespace caf;
namespace {
using fixture = test_coordinator_fixture<>;
} // namespace
BEGIN_FIXTURE_SCOPE(fixture)
SCENARIO("actions wrap function calls") { SCENARIO("actions wrap function calls") {
GIVEN("an action wrapping a lambda") { GIVEN("an action wrapping a lambda") {
WHEN("running the action") { WHEN("running the action") {
...@@ -69,3 +77,23 @@ SCENARIO("actions wrap function calls") { ...@@ -69,3 +77,23 @@ SCENARIO("actions wrap function calls") {
} }
} }
} }
SCENARIO("actors run actions that they receive") {
GIVEN("a scheduled actor") {
WHEN("sending it an action") {
THEN("the actor runs the action regardless of its behavior") {
auto aut = sys.spawn([](caf::event_based_actor*) -> behavior {
return {
[](int32_t x) { return x; },
};
});
auto n = 0;
inject((detail::action),
to(aut).with(detail::make_action([&n] { ++n; })));
CHECK_EQ(n, 1);
}
}
}
}
END_FIXTURE_SCOPE()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment