Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
util::Channel< T, P, C >::Receiver Class Reference

The receiving end of a channel. More...

#include <Channel.hpp>

Public Member Functions

 Receiver (Receiver &&)=default
 Receiver (Receiver const &)=default
 Receiver (Receiver const &)=delete
Receiver & operator= (Receiver &&)=default
Receiver & operator= (Receiver const &)=default
Receiver & operator= (Receiver const &)=delete
std::optional< T > tryReceive ()
 Attempts to receive data from the channel without blocking.
std::optional< T > asyncReceive (boost::asio::yield_context yield)
 Asynchronously receives data from the channel using a coroutine.
void asyncReceive (std::invocable< std::optional< std::remove_cvref_t< T > > > auto &&fn)
 Asynchronously receives data from the channel using a callback.
bool isClosed () const
 Checks if the channel is closed.

Friends

class Channel< T, P, C >

Detailed Description

template<typename T, ProducerType P = ProducerType::Multi, ConsumerType C = ConsumerType::Multi>
class util::Channel< T, P, C >::Receiver

The receiving end of a channel.

Receiver is movable. For multi-consumer channels, Receiver is also copyable. Multiple receivers can consume from the same multi-consumer channel concurrently. When all Receiver instances are destroyed, the channel is closed and senders will fail to send.

Member Function Documentation

◆ asyncReceive() [1/2]

template<typename T, ProducerType P = ProducerType::Multi, ConsumerType C = ConsumerType::Multi>
std::optional< T > util::Channel< T, P, C >::Receiver::asyncReceive ( boost::asio::yield_context yield)
inlinenodiscard

Asynchronously receives data from the channel using a coroutine.

Blocks the coroutine until data is available or the channel is closed.

Parameters
yieldThe Boost.Asio yield context for coroutine suspension
Returns
std::optional containing the received value, or std::nullopt if the channel is closed

◆ asyncReceive() [2/2]

template<typename T, ProducerType P = ProducerType::Multi, ConsumerType C = ConsumerType::Multi>
void util::Channel< T, P, C >::Receiver::asyncReceive ( std::invocable< std::optional< std::remove_cvref_t< T > > > auto && fn)
inline

Asynchronously receives data from the channel using a callback.

The callback is invoked when data is available or the channel is closed.

Parameters
fnCallback function invoked with std::optional containing the value, or std::nullopt if closed

◆ isClosed()

template<typename T, ProducerType P = ProducerType::Multi, ConsumerType C = ConsumerType::Multi>
bool util::Channel< T, P, C >::Receiver::isClosed ( ) const
inlinenodiscard

Checks if the channel is closed.

A channel is closed when all Sender instances have been destroyed.

Returns
true if the channel is closed, false otherwise

◆ tryReceive()

template<typename T, ProducerType P = ProducerType::Multi, ConsumerType C = ConsumerType::Multi>
std::optional< T > util::Channel< T, P, C >::Receiver::tryReceive ( )
inline

Attempts to receive data from the channel without blocking.

Returns
std::optional containing the received value, or std::nullopt if the channel is empty or closed

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