Corium 1.1.0
High-Performance Zero-Heap C++20 MPSC Application Runtime
Loading...
Searching...
No Matches
corium::async::Channel< T, Capacity > Class Template Reference

Statically allocated bounded asynchronous channel for typed producer-consumer coroutines. More...

#include <Channel.hpp>

+ Collaboration diagram for corium::async::Channel< T, Capacity >:

Classes

struct  PopAwaiter
 Awaiter for popping an item asynchronously (suspends if channel is empty). More...
 
struct  PushAwaiter
 Awaiter for pushing an item asynchronously (suspends if channel is full). More...
 

Public Types

using ValueType = T
 

Public Member Functions

constexpr Channel () noexcept=default
 
 Channel (const Channel &)=delete
 
void close () noexcept
 Close the channel. No more pushes will succeed. Remaining elements can still be popped.
 
bool empty () const noexcept
 Check if channel is empty.
 
bool full () const noexcept
 Check if channel is full.
 
bool isClosed () const noexcept
 Check if channel is closed.
 
Channeloperator= (const Channel &)=delete
 
PopAwaiter pop () noexcept
 Pop an item from the channel asynchronously.
 
PushAwaiter push (T val) noexcept
 Push an item into the channel asynchronously with backpressure suspension.
 
size_t size () const noexcept
 Number of elements currently in the channel.
 
bool tryPop (T &out) noexcept
 Non-blocking attempt to pop an item from the channel.
 
bool tryPush (T value) noexcept
 Non-blocking attempt to push an item into the channel.
 
 ~Channel ()
 

Detailed Description

template<typename T, size_t Capacity = 16>
class corium::async::Channel< T, Capacity >

Statically allocated bounded asynchronous channel for typed producer-consumer coroutines.

Template Parameters
TElement type transferred through the channel.
CapacityMaximum capacity of the channel ring buffer (must be power of two or positive).

Member Typedef Documentation

◆ ValueType

template<typename T , size_t Capacity = 16>
using corium::async::Channel< T, Capacity >::ValueType = T

Constructor & Destructor Documentation

◆ Channel() [1/2]

template<typename T , size_t Capacity = 16>
constexpr corium::async::Channel< T, Capacity >::Channel ( )
constexprdefaultnoexcept

◆ ~Channel()

template<typename T , size_t Capacity = 16>
corium::async::Channel< T, Capacity >::~Channel ( )
inline
+ Here is the call graph for this function:

◆ Channel() [2/2]

template<typename T , size_t Capacity = 16>
corium::async::Channel< T, Capacity >::Channel ( const Channel< T, Capacity > &  )
delete

Member Function Documentation

◆ close()

template<typename T , size_t Capacity = 16>
void corium::async::Channel< T, Capacity >::close ( )
inlinenoexcept

Close the channel. No more pushes will succeed. Remaining elements can still be popped.

+ Here is the caller graph for this function:

◆ empty()

template<typename T , size_t Capacity = 16>
bool corium::async::Channel< T, Capacity >::empty ( ) const
inlinenoexcept

Check if channel is empty.

+ Here is the call graph for this function:

◆ full()

template<typename T , size_t Capacity = 16>
bool corium::async::Channel< T, Capacity >::full ( ) const
inlinenoexcept

Check if channel is full.

+ Here is the call graph for this function:

◆ isClosed()

template<typename T , size_t Capacity = 16>
bool corium::async::Channel< T, Capacity >::isClosed ( ) const
inlinenoexcept

Check if channel is closed.

+ Here is the caller graph for this function:

◆ operator=()

template<typename T , size_t Capacity = 16>
Channel & corium::async::Channel< T, Capacity >::operator= ( const Channel< T, Capacity > &  )
delete

◆ pop()

template<typename T , size_t Capacity = 16>
PopAwaiter corium::async::Channel< T, Capacity >::pop ( )
inlinenoexcept

Pop an item from the channel asynchronously.

Returns
Awaiter resolving to std::optional<T> (std::nullopt when closed and drained).

◆ push()

template<typename T , size_t Capacity = 16>
PushAwaiter corium::async::Channel< T, Capacity >::push ( val)
inlinenoexcept

Push an item into the channel asynchronously with backpressure suspension.

Parameters
valItem to push.
Returns
Awaiter resolving to true if pushed, false if channel closed.

◆ size()

template<typename T , size_t Capacity = 16>
size_t corium::async::Channel< T, Capacity >::size ( ) const
inlinenoexcept

Number of elements currently in the channel.

+ Here is the caller graph for this function:

◆ tryPop()

template<typename T , size_t Capacity = 16>
bool corium::async::Channel< T, Capacity >::tryPop ( T &  out)
inlinenoexcept

Non-blocking attempt to pop an item from the channel.

Parameters
outVariable to receive the popped item.
Returns
true if popped; false if channel is empty.
+ Here is the caller graph for this function:

◆ tryPush()

template<typename T , size_t Capacity = 16>
bool corium::async::Channel< T, Capacity >::tryPush ( value)
inlinenoexcept

Non-blocking attempt to push an item into the channel.

Parameters
valueItem to push.
Returns
true if pushed; false if channel is full or closed.
+ Here is the caller graph for this function:

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