libcaf  0.16.0
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...
 
struct  mailbox_policy
 Configures the FIFO inbox with two nested queues: 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 super = extended_base
 Base type.
 
using default_queue = intrusive::drr_cached_queue< policy::normal_messages >
 Stores asynchronous messages with default priority.
 
using urgent_queue = intrusive::drr_cached_queue< policy::urgent_messages >
 Stores asynchronous messages with hifh priority.
 
using mailbox_type = intrusive::fifo_inbox< mailbox_policy >
 A queue optimized for single-reader-many-writers.
 
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.
 
mailbox_typemailbox ()
 Returns the queue for storing incoming messages.
 

Detailed Description

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

Member Function Documentation

◆ await_data()

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.

◆ do_receive()

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;
(
on<int>() >> int_fun,
on<float>() >> float_fun
)
.until([&]() { return (++i >= 10); };

◆ fail_state()

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.

◆ receive()

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

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

◆ receive_for()

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() [1/2]

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() [2/2]

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: