C/C++ API Reference
Loading...
Searching...
No Matches
pw::async2::Receiver< T > Class Template Reference

Overview

template<typename T>
class pw::async2::Receiver< T >

A receiver which reads values from an asynchronous channel.

Public Member Functions

 Receiver (const Receiver &other)=delete
 
Receiveroperator= (const Receiver &other)=delete
 
 Receiver (Receiver &&other) noexcept
 
Receiveroperator= (Receiver &&other) noexcept
 
Result< T > BlockingReceive (Dispatcher &dispatcher, chrono::SystemClock::duration timeout=kWaitForever)
 
ReceiveFuture< T > Receive ()
 
Result< T > TryReceive ()
 
void Disconnect ()
 
bool is_open () const
 Returns true if the channel is open.
 

Friends

template<typename U >
class internal::Channel
 
template<typename U >
std::optional< std::tuple< MpscChannelHandle< U >, Receiver< U > > > CreateMpscChannel (Allocator &, uint16_t)
 
template<typename U , uint16_t kCapacity>
std::tuple< MpscChannelHandle< U >, Receiver< U > > CreateMpscChannel (ChannelStorage< U, kCapacity > &storage)
 
template<typename U >
std::optional< std::tuple< SpscChannelHandle< U >, Sender< U >, Receiver< U > > > CreateSpscChannel (Allocator &, uint16_t)
 
template<typename U , uint16_t kCapacity>
std::tuple< SpscChannelHandle< U >, Sender< U >, Receiver< U > > CreateSpscChannel (ChannelStorage< U, kCapacity > &storage)
 

Member Function Documentation

◆ BlockingReceive()

template<typename T >
Result< T > pw::async2::Receiver< T >::BlockingReceive ( Dispatcher dispatcher,
chrono::SystemClock::duration  timeout = kWaitForever 
)
inline

Reads a value from the channel, blocking until it is available.

Returns

This operation blocks the running thread until it is complete. It must not be called from an async context, or it will likely deadlock.

◆ Disconnect()

template<typename T >
void pw::async2::Receiver< T >::Disconnect ( )
inline

Removes this receiver from its channel, preventing the receiver from reading further values.

The channel may remain open if other receivers exist.

◆ Receive()

template<typename T >
ReceiveFuture< T > pw::async2::Receiver< T >::Receive ( )
inline

Reads a value from the channel, blocking until it is available.

Returns a Future<std::optional<T>> which resolves to a T value if the read is successful, or std::nullopt if the channel is closed.

If there are multiple receivers for a channel, each of them compete for exclusive values.

◆ TryReceive()

template<typename T >
Result< T > pw::async2::Receiver< T >::TryReceive ( )
inline

Reads a value from the channel if one is available.

Returns

Friends And Related Function Documentation

◆ CreateMpscChannel

template<typename T >
template<typename U >
std::optional< std::tuple< MpscChannelHandle< U >, Receiver< U > > > CreateMpscChannel ( Allocator alloc,
uint16_t  capacity 
)
friend

Creates a dynamically allocated multi-producer, single-consumer channel with a fixed storage capacity.

Returns a handle to the channel which may be used to create senders. After all desired senders are created, the handle can be dropped without affecting the channel.

All allocation occurs during the creation of the channel. After this function returns, usage of the channel is guaranteed not to allocate. If allocation fails, returns std::nullopt.

The channel remains open as long as at least either a handle, or at least one sender and one receiver exist.

◆ CreateSpscChannel

template<typename T >
template<typename U >
std::optional< std::tuple< SpscChannelHandle< U >, Sender< U >, Receiver< U > > > CreateSpscChannel ( Allocator alloc,
uint16_t  capacity 
)
friend

Creates a dynamically allocated single-producer, single-consumer channel with a fixed storage capacity.

Returns a handle to the channel alongside the sender and receiver. The handle can be used to forcefully close the channel. If that is not required, it can be dropped without affecting the channel.

All allocation occurs during the creation of the channel. After this function returns, usage of the channel is guaranteed not to allocate. If allocation fails, returns std::nullopt.

The channel remains open as long as at least either a handle, or at least one sender and one receiver exist.


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