Loading...
Searching...
No Matches
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>`

Inheritance diagram for caf::blocking_actor:

## Classes

struct | mailbox_policy
| Configures the FIFO inbox with two nested queues: More...
class | receive_cond
| Represents pre- and postconditions for receive loops. More...
class | accept_one_cond
| Pseudo receive condition modeling a single receive. More...
struct | receive_while_helper
| Implementation helper for blocking_actor::receive_while. More...
struct | receive_for_helper
| Implementation helper for blocking_actor::receive_for. More...
struct | do_receive_helper
| Implementation helper for blocking_actor::do_receive. More...

## Public Types

using | super = extended_base
| Base type.
using | normal_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 high 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
mailbox_element * | peek_at_next_mailbox_element () 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.
template<class T>
receive_for_helper< T > | receive_for (T &begin, T end)
| Receives messages for range [begin, first).
receive_while_helper | receive_while (std::function< bool()> stmt)
| Receives messages as long as stmt returns true.
receive_while_helper | receive_while (const bool &ref)
| Receives messages as long as ref is true.
template<class... Ts>
do_receive_helper | do_receive (Ts &&... xs)
| Receives messages until stmt returns true.
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.
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.
virtual mailbox_element_ptr | dequeue ()
| Returns the next element from the mailbox or nullptr.
mailbox_type & | mailbox ()
| 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

## 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;
do_receive
(
on<int>() >> int_fun,
on<float>() >> float_fun
)
.until([&]() { return (++i >= 10); };
caf::blocking_actor::do_receive
do_receive_helper do_receive(Ts &&... xs)
Receives messages until stmt returns true.
Definition blocking_actor.hpp:332

## 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_for()

template<class T>

receive_for_helper< T > caf::blocking_actor::receive_for | ( | T & | begin,
|  | T | 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;
}
);
caf::blocking_actor::receive_for
receive_for_helper< T > receive_for(T &begin, T end)
Receives messages for range [begin, first).
Definition blocking_actor.hpp:287

## receive_while() [1/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) (
...
);
caf::blocking_actor::receive_while
receive_while_helper receive_while(std::function< bool()> stmt)
Receives messages as long as stmt returns true.

## receive_while() [2/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); }) (
...
);

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

- /build/actor-framework-Z9pIPl/actor-framework-0.17.6/libcaf_core/caf/blocking_actor.hpp