stlab 2.3.0
Modern, modular C++ algorithms, data structures, and concurrency primitives
Loading...
Searching...
No Matches
stlab::receiver< T > Class Template Reference

Receiving end of a CSP channel. More...

#include <channel.hpp>

Public Types

using result_type

Public Member Functions

 receiver (const receiver &x)
 receiver (receiver &&) noexcept=default
auto operator= (const receiver &x) -> receiver &
auto operator= (receiver &&x) noexcept -> receiver &=default
void set_ready ()
 Marks this receiver ready so values may flow through the graph.
void swap (receiver &x) noexcept
auto ready () const -> bool
 Returns true if set_ready() was called on this receiver.
Attach process (<tt>operator|</tt>)

Creates a new downstream receiver and attaches a process. f may be a unary function, a process with await/yield, or detail::annotated_process from buffer_size / executor via operator&. L-value processes may be wrapped in std::reference_wrapper.

template<typename F>
auto operator| (F &&f) const
 Attaches f and returns a new receiver (inherits executor unless overridden).
template<typename F>
auto operator| (detail::annotated_process< F > ap)
 Attaches an annotated process (buffer size and/or executor from operator&).
template<typename F>
auto operator| (executor_task_pair< F > etp)
 Attaches etp (process plus executor from operator&).
auto operator| (sender< T > send)
 Forwards values into downstream send.

Detailed Description

template<typename T>
class stlab::receiver< T >

Receiving end of a CSP channel.

Each receiver has an attached process that runs when a value is sent through the paired sender. The process may be an n-ary function object (arity matches the number of upstream receivers) or a type with await() and yield() methods.

Repeated operator| on the same receiver splits the stream: results are copied to every downstream channel when T is copyable; for move-only T, each call overwrites the previous downstream attachment.

If the process throws, the exception is passed to a downstream process that implements set_error(); otherwise this process is closed. All receivers that participate in a graph must call set_ready() or data cannot flow.

Specialize stlab::smart_test when T is e.g. a container of non-copyable elements so move-only dispatch is correct (std::is_copy_constructible is defective for such types).


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