libcaf  0.15.3
Classes | Public Types | Public Member Functions | List of all members
caf::blocking_actor Class Reference

A thread-mapped or context-switching actor using a blocking receive rather than a behavior-stack based message processing. More...

#include <blocking_actor.hpp>

Inherits local_actor, with< mixin::requester, mixin::sender, mixin::subscriber >, and caf::dynamically_typed_actor_base.

Classes

class  accept_one_cond
 Pseudo receive condition modeling a single receive. More...
 
struct  do_receive_helper
 Implementation helper for blocking_actor::do_receive. More...
 
class  receive_cond
 Represents pre- and postconditions for receive loops. More...
 
struct  receive_for_helper
 Implementation helper for blocking_actor::receive_for. More...
 
struct  receive_while_helper
 Implementation helper for blocking_actor::receive_while. More...
 

Public Types

using timeout_type = std::chrono::high_resolution_clock::time_point
 Absolute timeout type.
 
using behavior_type = behavior
 Supported behavior type.
 
using signatures = none_t
 Declared message passing interface.
 

Public Member Functions

 blocking_actor (actor_config &cfg)
 
void enqueue (mailbox_element_ptr, execution_unit *) override
 
const char * name () const override
 
void launch (execution_unit *eu, bool lazy, bool hide) override
 
virtual void act ()
 Implements the actor's behavior.
 
template<class... Ts>
void receive (Ts &&...xs)
 Dequeues the next message from the mailbox that is matched by given behavior. More...
 
template<class T >
receive_for_helper< T > receive_for (T &begin, T end)
 Receives messages for range [begin, first). More...
 
receive_while_helper receive_while (std::function< bool()> stmt)
 Receives messages as long as stmt returns true. More...
 
receive_while_helper receive_while (const bool &ref)
 Receives messages as long as ref is true. More...
 
template<class... Ts>
do_receive_helper do_receive (Ts &&...xs)
 Receives messages until stmt returns true. More...
 
void await_all_other_actors_done ()
 Blocks this actor until all other actors are done.
 
template<class... Ts>
void wait_for (Ts &&...xs)
 Blocks this actor until all xs... have terminated.
 
void fail_state (error err)
 Sets a user-defined exit reason err. More...
 
virtual void await_data ()
 Blocks until at least one message is in the mailbox.
 
virtual bool await_data (timeout_type timeout)
 Blocks until at least one message is in the mailbox or the absolute timeout was reached. More...
 
virtual mailbox_element_ptr dequeue ()
 Returns the next element from the mailbox or nullptr. More...
 

Detailed Description

A thread-mapped or context-switching actor using a blocking receive rather than a behavior-stack based message processing.

Member Function Documentation

virtual bool caf::blocking_actor::await_data ( timeout_type  timeout)
virtual

Blocks until at least one message is in the mailbox or the absolute timeout was reached.

virtual mailbox_element_ptr caf::blocking_actor::dequeue ( )
virtual

Returns the next element from the mailbox or nullptr.

The default implementation simply returns next_message().

template<class... Ts>
do_receive_helper caf::blocking_actor::do_receive ( Ts &&...  xs)

Receives messages until stmt returns true.

Semantically equal to: do { receive(...); } while (stmt() == false);

Usage example:

  • ~~~ int i = 0; do_receive ( on<int>() >> int_fun, on<float>() >> float_fun ) .until([&]() { return (++i >= 10); };
  • ~~~
void caf::blocking_actor::fail_state ( error  err)

Sets a user-defined exit reason err.

This reason is signalized to other actors after act() returns.

template<class... Ts>
void caf::blocking_actor::receive ( Ts &&...  xs)

Dequeues the next message from the mailbox that is matched by given behavior.

template<class T >
receive_for_helper<T> caf::blocking_actor::receive_for ( T &  begin,
end 
)

Receives messages for range [begin, first).

Semantically equal to: for ( ; begin != end; ++begin) { receive(...); }.

Usage example:

  • ~~~ int i = 0; receive_for(i, 10) ( [&](get_atom) { return i; } );
  • ~~~
receive_while_helper caf::blocking_actor::receive_while ( std::function< bool()>  stmt)

Receives messages as long as stmt returns true.

Semantically equal to: while (stmt()) { receive(...); }.

Usage example:

  • ~~~ int i = 0; receive_while([&]() { return (++i <= 10); }) ( ... );
  • ~~~
receive_while_helper caf::blocking_actor::receive_while ( const bool &  ref)

Receives messages as long as ref is true.

Semantically equal to: while (ref) { receive(...); }.

Usage example:

  • ~~~ bool running = true; receive_while(running) ( ... );
  • ~~~

The documentation for this class was generated from the following file: