Commit 817ea66b authored by Dominik Charousset's avatar Dominik Charousset

Fix anon_send in composable behaviors

parent d8884198
...@@ -117,15 +117,20 @@ public: ...@@ -117,15 +117,20 @@ public:
// -- spawn functions -------------------------------------------------------- // -- spawn functions --------------------------------------------------------
template <class T, spawn_options Os = no_spawn_options, class... Ts> template <class T, spawn_options Os = no_spawn_options, class... Ts>
typename infer_handle_from_class<T>::type infer_handle_from_class_t<T> spawn(Ts&&... xs) {
spawn(Ts&&... xs) {
actor_config cfg{context()}; actor_config cfg{context()};
return eval_opts(Os, system().spawn_class<T, make_unbound(Os)>(cfg, std::forward<Ts>(xs)...)); return eval_opts(Os, system().spawn_class<T, make_unbound(Os)>(cfg, std::forward<Ts>(xs)...));
} }
template <class T, spawn_options Os = no_spawn_options>
infer_handle_from_state_t<T> spawn() {
using impl = composable_behavior_based_actor<T>;
actor_config cfg{context()};
return eval_opts(Os, system().spawn_class<impl, make_unbound(Os)>(cfg));
}
template <spawn_options Os = no_spawn_options, class F, class... Ts> template <spawn_options Os = no_spawn_options, class F, class... Ts>
typename infer_handle_from_fun<F>::type infer_handle_from_fun_t<F> spawn(F fun, Ts&&... xs) {
spawn(F fun, Ts&&... xs) {
actor_config cfg{context()}; actor_config cfg{context()};
return eval_opts(Os, system().spawn_functor<make_unbound(Os)>(cfg, fun, std::forward<Ts>(xs)...)); return eval_opts(Os, system().spawn_functor<make_unbound(Os)>(cfg, fun, std::forward<Ts>(xs)...));
} }
...@@ -377,10 +382,6 @@ protected: ...@@ -377,10 +382,6 @@ protected:
std::function<behavior (local_actor*)> initial_behavior_fac_; std::function<behavior (local_actor*)> initial_behavior_fac_;
}; };
/// A smart pointer to a {@link local_actor} instance.
/// @relates local_actor
using local_actor_ptr = intrusive_ptr<local_actor>;
} // namespace caf } // namespace caf
#endif // CAF_LOCAL_ACTOR_HPP #endif // CAF_LOCAL_ACTOR_HPP
...@@ -143,7 +143,7 @@ public: ...@@ -143,7 +143,7 @@ public:
>::value, >::value,
"this actor does not accept the response message"); "this actor does not accept the response message");
dptr()->system().scheduler().delayed_send( dptr()->system().scheduler().delayed_send(
rtime, this->ctrl(), actor_cast<strong_actor_ptr>(dest), rtime, dptr()->ctrl(), actor_cast<strong_actor_ptr>(dest),
message_id::make(P), make_message(std::forward<Ts>(xs)...)); message_id::make(P), make_message(std::forward<Ts>(xs)...));
} }
......
...@@ -52,7 +52,7 @@ public: ...@@ -52,7 +52,7 @@ public:
/// @private /// @private
actor_control_block* get() const { actor_control_block* get() const {
return actor_control_block::from(view_.selfptr()); return view_.ctrl();
} }
private: private:
......
...@@ -34,7 +34,10 @@ class typed_actor_view : public extend<typed_actor_view_base, ...@@ -34,7 +34,10 @@ class typed_actor_view : public extend<typed_actor_view_base,
typed_actor_view<Sigs...>>::template typed_actor_view<Sigs...>>::template
with<mixin::sender, mixin::requester> { with<mixin::sender, mixin::requester> {
public: public:
typed_actor_view(scheduled_actor* selfptr) : self_(selfptr) { /// Stores the template parameter pack.
using signatures = detail::type_list<Sigs...>;
typed_actor_view(scheduled_actor* ptr) : self_(ptr) {
// nop // nop
} }
...@@ -48,6 +51,11 @@ public: ...@@ -48,6 +51,11 @@ public:
return self_->spawn<T, Os>(std::forward<Ts>(xs)...); return self_->spawn<T, Os>(std::forward<Ts>(xs)...);
} }
template <class T, spawn_options Os = no_spawn_options>
infer_handle_from_state_t<T> spawn() {
return self_->spawn<T, Os>();
}
template <spawn_options Os = no_spawn_options, class F, class... Ts> template <spawn_options Os = no_spawn_options, class F, class... Ts>
typename infer_handle_from_fun<F>::type typename infer_handle_from_fun<F>::type
spawn(F fun, Ts&&... xs) { spawn(F fun, Ts&&... xs) {
...@@ -96,8 +104,8 @@ public: ...@@ -96,8 +104,8 @@ public:
} }
/// @private /// @private
scheduled_actor* selfptr() const { actor_control_block* ctrl() const {
return self_; return actor_control_block::from(self_);;
} }
private: private:
......
...@@ -200,6 +200,30 @@ protected: ...@@ -200,6 +200,30 @@ protected:
std::unordered_map<counting_string, counting_string> values_; std::unordered_map<counting_string, counting_string> values_;
}; };
using delayed_testee_actor = typed_actor<reacts_to<int>,
replies_to<bool>::with<int>,
reacts_to<std::string>>;
class delayed_testee : public composable_behavior<delayed_testee_actor> {
public:
result<void> operator()(int x) override {
CAF_CHECK_EQUAL(x, 42);
self->delayed_anon_send(self, std::chrono::milliseconds(10), true);
return unit;
}
result<int> operator()(bool x) override {
CAF_CHECK_EQUAL(x, true);
self->delayed_send(self, std::chrono::milliseconds(10), "hello");
return 0;
}
result<void> operator()(param<std::string> x) override {
CAF_CHECK_EQUAL(x.get(), "hello");
return unit;
}
};
struct fixture { struct fixture {
fixture() : system(cfg) { fixture() : system(cfg) {
// nop // nop
...@@ -320,4 +344,10 @@ CAF_TEST(param_detaching) { ...@@ -320,4 +344,10 @@ CAF_TEST(param_detaching) {
CAF_CHECK_EQUAL(counting_strings_destroyed.load(), 11); CAF_CHECK_EQUAL(counting_strings_destroyed.load(), 11);
} }
CAF_TEST(delayed_sends) {
scoped_actor self{system};
auto testee = self->spawn<delayed_testee>();
self->send(testee, 42);
}
CAF_TEST_FIXTURE_SCOPE_END() CAF_TEST_FIXTURE_SCOPE_END()
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