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

The sending end of a channel. More...

#include <Channel.hpp>

Public Member Functions

 Sender (Sender &&)=default
 Sender (Sender const &)=default
 Sender (Sender const &)=delete
Sender & operator= (Sender &&)=default
Sender & operator= (Sender const &)=default
Sender & operator= (Sender const &)=delete
template<typename D>
requires (std::convertible_to<std::remove_cvref_t<D>, std::remove_cvref_t<T>>)
bool asyncSend (D &&data, boost::asio::yield_context yield)
 Asynchronously sends data through the channel using a coroutine.
template<typename D>
requires (std::convertible_to<std::remove_cvref_t<D>, std::remove_cvref_t<T>>)
void asyncSend (D &&data, std::invocable< bool > auto &&fn)
 Asynchronously sends data through the channel using a callback.
template<typename D>
requires (std::convertible_to<std::remove_cvref_t<D>, std::remove_cvref_t<T>>)
bool trySend (D &&data)
 Attempts to send data through the channel without blocking.

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 >::Sender

The sending end of a channel.

Sender is movable. For multi-producer channels, Sender is also copyable. The channel remains open as long as at least one Sender exists. When all Sender instances are destroyed, the channel is closed and receivers will receive std::nullopt.

Member Function Documentation

◆ asyncSend() [1/2]

template<typename T, ProducerType P = ProducerType::Multi, ConsumerType C = ConsumerType::Multi>
template<typename D>
requires (std::convertible_to<std::remove_cvref_t<D>, std::remove_cvref_t<T>>)
bool util::Channel< T, P, C >::Sender::asyncSend ( D && data,
boost::asio::yield_context yield )
inline

Asynchronously sends data through the channel using a coroutine.

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

Template Parameters
DThe type of data to send (must be convertible to T)
Parameters
dataThe data to send
yieldThe Boost.Asio yield context for coroutine suspension
Returns
true if the data was sent successfully, false if the channel is closed

◆ asyncSend() [2/2]

template<typename T, ProducerType P = ProducerType::Multi, ConsumerType C = ConsumerType::Multi>
template<typename D>
requires (std::convertible_to<std::remove_cvref_t<D>, std::remove_cvref_t<T>>)
void util::Channel< T, P, C >::Sender::asyncSend ( D && data,
std::invocable< bool > auto && fn )
inline

Asynchronously sends data through the channel using a callback.

The callback is invoked when the send operation completes.

Template Parameters
DThe type of data to send (must be convertible to T)
Parameters
dataThe data to send
fnCallback function invoked with true if successful, false if the channel is closed

◆ trySend()

template<typename T, ProducerType P = ProducerType::Multi, ConsumerType C = ConsumerType::Multi>
template<typename D>
requires (std::convertible_to<std::remove_cvref_t<D>, std::remove_cvref_t<T>>)
bool util::Channel< T, P, C >::Sender::trySend ( D && data)
inline

Attempts to send data through the channel without blocking.

Template Parameters
DThe type of data to send (must be convertible to T)
Parameters
dataThe data to send
Returns
true if the data was sent successfully, false if the channel is full or closed

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