The receive
static member
function allows you to receive a message sent to the current actor.
unspecified-message-receiver receive(); class unspecified-message-receiver { // all constructors are private public: ~unspecified-message-receiver(); template<typename MsgType,typedef HandlerFunc> another-unspecified-message-receiver match(HandlerFunc&& func); };
Constructs a message-receiving object of unspecified type for the current actor that implements the specified interface for the unspecified-message-receiver described above.
Calling match()
on a receiver adds the specified MsgType
to the list of handled messages, and registers the specified handler
to be called when a message of that type is received. The specified
handler must be a function or a callable object such that func(msg)
is a valid expression, where msg
is an instance of the specified MsgType
.
Since match()
returns another message receiver type, calls to match()
may be chained.
e.g. jss::actor::receive()
.match<MessageType1>(handleType1) .match<MessageType2>([](MessageType2 msg){ do_something();}) .match<MessageType3>(Type3Handler());
The destructor of the last message receiver from a given receive()
call will block the current thread until a message that matches
the set of message types specified in the chained calls to match()
or a jss::stop_actor
has been received.
Any messages of other types received will be discarded. Once a
message has been received then the corresponding handler will be
invoked, and control returned to the function that called receive()
(unless the handler threw an exception).
jss::no_actor
if the current thread is not running an actor. jss::stop_actor
if a jss::stop_actor
message has been received. Any exceptions thrown by the message
handlers.
The completion of the call to jss::actor::send()
that posted a message synchronizes-with a
call to receive()
that receives the posted message.
#include <jss/actor.hpp>