Commit b3d70100 authored by Dominik Charousset's avatar Dominik Charousset

Add `scoped_actor` section to manual

parent 89112fed
...@@ -109,3 +109,25 @@ void foo(blocking_actor* self, actor testee) { ...@@ -109,3 +109,25 @@ void foo(blocking_actor* self, actor testee) {
); );
} }
\end{lstlisting} \end{lstlisting}
\subsection{Mixing Actors and Threads with Scoped Actors}
The class \lstinline^scoped_actor^ offers a simple way of communicating with CAF actors from non-actor contexts.
It overloads \lstinline^operator->^ to return a \lstinline^blocking_actor*^.
Hence, it behaves like the implicit \lstinline^self^ pointer in functor-based actors, only that it ceases to exist at scope end.
\begin{lstlisting}
void test() {
scoped_actor self;
// spawn some monitored actor
auto aut = self->spawn<monitored>(my_actor_impl);
self->sync_send(aut, "hi there").await(
... // handle response
);
// self will be destroyed automatically here; any
// actor monitoring it will receive down messages etc.
}
\end{lstlisting}
Note that \lstinline^scoped_actor^ throws an \lstinline^actor_exited^ exception when forced to quit for some reason, e.g., via an \lstinline^exit_msg^.
Whenever a \lstinline^scoped_actor^ might end up receiving an \lstinline^exit_msg^ (because it links itself to another actor for example), the caller either needs to handle the exception or the actor needs to process \lstinline^exit_msg^ manually via \lstinline^self->trap_exit(true)^.
No preview for this file type
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