Skip to main content
Pigweed's logo Pigweed
code_xml
  1. Home
  2. Reference
  3. C/C++
  4. pw_async2
  5. Channels
  6. pw::async2::Sender< T > Class Template Reference
Loading...
Searching...
No Matches
pw::async2::Sender< T > Class Template Reference

Overview

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

A sender which writes values to an asynchronous channel.

Public Member Functions

 Sender (const Sender &other)=delete
 
Sender & operator= (const Sender &other)=delete
 
 Sender (Sender &&other) noexcept
 
Sender & operator= (Sender &&other) noexcept
 
template<typename U >
SendFuture< T > Send (U &&value) const
 
SendFuture< T > Send () const
 
ReserveSendFuture< T > ReserveSend () const
 
Result< SendReservation< T > > TryReserveSend () const
 
template<typename U , int &... kExplicitGuard, std::enable_if_t< std::is_same_v<::cpp20::remove_cvref_t< U >, T >, bool > = true>
Status TrySend (U &&value) const
 
template<typename U , int &... kExplicitGuard, std::enable_if_t<!std::is_same_v<::cpp20::remove_cvref_t< U >, T > &&std::is_constructible_v< T, U >, bool > = true>
Status TrySend (U &&value) const
 
Status TrySend () const
 
template<typename U , int &... kExplicitGuard, std::enable_if_t< std::is_same_v<::cpp20::remove_cvref_t< U >, T >, bool > = true>
Status BlockingSend (Dispatcher &dispatcher, U &&value, chrono::SystemClock::duration timeout=internal::Channel< T >::kWaitForever) const
 
template<typename U , int &... kExplicitGuard, std::enable_if_t<!std::is_same_v<::cpp20::remove_cvref_t< U >, T > &&std::is_constructible_v< T, U >, bool > = true>
Status BlockingSend (Dispatcher &dispatcher, U &&value, chrono::SystemClock::duration timeout=internal::Channel< T >::kWaitForever) const
 
Status BlockingSend (Dispatcher &dispatcher, chrono::SystemClock::duration timeout=internal::Channel< T >::kWaitForever) const
 
void Disconnect ()
 
uint16_t remaining_capacity () const
 Returns the remaining capacity of the channel.
 
uint16_t capacity () const
 Returns the maximum capacity of the channel.
 
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< SpmcChannelHandle< U >, Sender< U > > > CreateSpmcChannel (Allocator &, uint16_t)
 
template<typename U , uint16_t kCapacity>
std::tuple< SpmcChannelHandle< U >, Sender< U > > CreateSpmcChannel (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

◆ BlockingSend() [1/3]

template<typename T >
Status pw::async2::Sender< T >::BlockingSend ( Dispatcher &  dispatcher,
chrono::SystemClock::duration  timeout = internal::Channel<T>::kWaitForever 
) const
inline

Synchronously attempts to send a notification on the channel, blocking until space is available or the channel is closed.

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

Returns

◆ BlockingSend() [2/3]

template<typename T >
template<typename U , int &... kExplicitGuard, std::enable_if_t< std::is_same_v<::cpp20::remove_cvref_t< U >, T >, bool > = true>
Status pw::async2::Sender< T >::BlockingSend ( Dispatcher &  dispatcher,
U &&  value,
chrono::SystemClock::duration  timeout = internal::Channel<T>::kWaitForever 
) const
inline

Synchronously attempts to send value to the channel, blocking until space is available or the channel is closed.

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

Returns

◆ BlockingSend() [3/3]

template<typename T >
template<typename U , int &... kExplicitGuard, std::enable_if_t<!std::is_same_v<::cpp20::remove_cvref_t< U >, T > &&std::is_constructible_v< T, U >, bool > = true>
Status pw::async2::Sender< T >::BlockingSend ( Dispatcher &  dispatcher,
U &&  value,
chrono::SystemClock::duration  timeout = internal::Channel<T>::kWaitForever 
) const
inline

Synchronously attempts to send value to the channel, blocking until space is available or the channel is closed.

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

Returns

◆ Disconnect()

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

Removes this sender from its channel, preventing it from writing further values.

The channel may remain open if other senders and receivers exist.

◆ ReserveSend()

template<typename T >
ReserveSendFuture< T > pw::async2::Sender< T >::ReserveSend ( ) const
inline

Returns a Future<std::optional<SendReservation>> which resolves to a SendReservation which can be used to write a value directly into the channel when space is available.

If the channel is closed, the future resolves to nullopt.

◆ Send()

template<typename T >
template<typename U >
SendFuture< T > pw::async2::Sender< T >::Send ( U &&  value) const
inline

Sends value through the channel, blocking until there is space.

Returns a Future<bool> which resolves to true if the value was successfully sent to the channel, or false if the channel is closed.

Note that a value being sent successfully does not guarantee that it will be read. If all corresponding receivers disconnect, any values still buffered in the channel are lost.

◆ TryReserveSend()

template<typename T >
Result< SendReservation< T > > pw::async2::Sender< T >::TryReserveSend ( ) const
inline

Synchronously attempts to reserve a slot in the channel.

This operation is thread-safe and may be called from outside of an async context.

Returns

◆ TrySend() [1/3]

template<typename T >
Status pw::async2::Sender< T >::TrySend ( ) const
inline

Synchronously attempts to send a notification if there is space in the channel.

This operation is thread-safe and may be called from outside of an async context.

Returns

◆ TrySend() [2/3]

template<typename T >
template<typename U , int &... kExplicitGuard, std::enable_if_t< std::is_same_v<::cpp20::remove_cvref_t< U >, T >, bool > = true>
Status pw::async2::Sender< T >::TrySend ( U &&  value) const
inline

Synchronously attempts to send value if there is space in the channel.

This operation is thread-safe and may be called from outside of an async context.

Returns

◆ TrySend() [3/3]

template<typename T >
template<typename U , int &... kExplicitGuard, std::enable_if_t<!std::is_same_v<::cpp20::remove_cvref_t< U >, T > &&std::is_constructible_v< T, U >, bool > = true>
Status pw::async2::Sender< T >::TrySend ( U &&  value) const
inline

Synchronously attempts to send value if there is space in the channel.

This operation is thread-safe and may be called from outside of an async context.

Returns

Friends And Related Function Documentation

◆ CreateSpmcChannel

template<typename T >
template<typename U >
std::optional< std::tuple< SpmcChannelHandle< U >, Sender< U > > > CreateSpmcChannel ( Allocator &  alloc,
uint16_t  capacity 
)
friend

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

Returns a handle to the channel which may be used to create receivers. After all desired receivers 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: