7 #include "caf/detail/behavior_impl.hpp" 8 #include "caf/detail/core_export.hpp" 9 #include "caf/detail/type_traits.hpp" 10 #include "caf/none.hpp" 11 #include "caf/timeout_definition.hpp" 12 #include "caf/timespan.hpp" 13 #include "caf/unsafe_behavior_init.hpp" 16 #include <type_traits> 20 class message_handler;
44 template <
class T,
class... Ts>
46 if constexpr (is_timeout_definition_v<T>
47 || (is_timeout_definition_v<Ts> || ...)) {
48 legacy_assign(std::move(arg), std::forward<Ts>(args)...);
50 impl_ = detail::make_behavior(std::move(arg), std::forward<Ts>(args)...);
56 [[deprecated(
"use idle timeouts instead of 'after >> ...'")]]
58 : impl_(
detail::make_behavior(tdef)) {
63 template <
class... Ts>
64 [[deprecated(
"use idle timeouts instead of 'after >> ...'")]]
66 static_assert(
sizeof...(Ts) > 0,
"assign() called without arguments");
67 impl_ = detail::make_behavior(std::forward<Ts>(xs)...);
71 template <
class T,
class... Ts>
73 if constexpr (is_timeout_definition_v<T>
74 || (is_timeout_definition_v<Ts> || ...)) {
75 legacy_assign(std::forward<T>(arg), std::forward<Ts>(args)...);
77 impl_ = detail::make_behavior(std::forward<T>(arg),
78 std::forward<Ts>(args)...);
83 impl_.swap(other.impl_);
98 impl_->handle_timeout();
104 return impl_->timeout();
109 return impl_ ? impl_->invoke(xs) : std::nullopt;
114 return impl_ ? impl_->invoke(f, xs) :
false;
118 operator bool()
const {
119 return static_cast<bool>(impl_);
126 const impl_ptr& as_behavior_impl()
const {
130 behavior(impl_ptr ptr) : impl_(std::move(ptr)) {
139 return std::move(*
this);
Describes the behavior of an actor, i.e., provides a message handler and an optional timeout...
Definition: behavior.hpp:24
std::chrono::duration< int64_t, std::nano > timespan
A portable timespan type with nanosecond resolution.
Definition: timespan.hpp:14
Empty struct tag for constructing a typed behavior from an untyped behavior.
Definition: unsafe_behavior_init.hpp:10
Indicates that the thread has been launched by request of a user without using any of the default mec...
Describes a fixed-length, copy-on-write, type-erased tuple with elements of any type.
Definition: message.hpp:32
behavior(timeout_definition< F > tdef)
Creates a behavior from tdef without message handler.
Definition: behavior.hpp:57
void legacy_assign(Ts &&... xs)
Assigns new handlers.
Definition: behavior.hpp:65
void handle_timeout()
Invokes the timeout callback if set.
Definition: behavior.hpp:97
behavior(T arg, Ts &&... args)
The list of arguments can contain match expressions, message handlers, and up to one timeout (if set...
Definition: behavior.hpp:45
Definition: type_id_list.test.cpp:11
timespan timeout() const noexcept
Returns the timespan after which receive operations using this behavior should time out...
Definition: behavior.hpp:103
std::optional< message > operator()(message &xs)
Runs this handler and returns its (optional) result.
Definition: behavior.hpp:108
void assign(T &&arg, Ts &&... args)
Assigns new handlers.
Definition: behavior.hpp:72
Inspects the result of message handlers and triggers type-depended actions such as generating result ...
Definition: invoke_result_visitor.hpp:24
Root namespace of libcaf.
Definition: custom_types_4.cpp:139
A partial function implementation used to process a message.
Definition: message_handler.hpp:27
bool operator()(detail::invoke_result_visitor &f, message &xs)
Runs this handler with callback.
Definition: behavior.hpp:113