Aria 2.0.0
C++23 MVVM framework (C++20 minimum) — reactive, coroutine-first, ABI-layered
Loading...
Searching...
No Matches
aria::async::Channel< T > Class Template Reference

#include <channel.hpp>

Public Member Functions

 Channel (std::size_t capacity=std::size_t(-1))
 Channel (const Channel &)=delete
Channeloperator= (const Channel &)=delete
 Channel (Channel &&)=delete
Channeloperator= (Channel &&)=delete
 ~Channel ()
 Releases every still-parked sender / receiver.
auto send (T value)
auto recv ()
void close ()
 Mark the channel closed and release EVERY parked coroutine.
bool is_closed () const
std::size_t size () const

Constructor & Destructor Documentation

◆ Channel() [1/3]

template<typename T>
aria::async::Channel< T >::Channel ( std::size_t capacity = std::size_t(-1))
inlineexplicit

◆ Channel() [2/3]

template<typename T>
aria::async::Channel< T >::Channel ( const Channel< T > & )
delete

◆ Channel() [3/3]

template<typename T>
aria::async::Channel< T >::Channel ( Channel< T > && )
delete

◆ ~Channel()

template<typename T>
aria::async::Channel< T >::~Channel ( )
inline

Releases every still-parked sender / receiver.

Destroying a channel that still has waiters would otherwise leak one coroutine frame per waiter: nothing else holds those handles, so they could never be resumed or destroyed. close() is idempotent and resumes outside the lock, so calling it here is safe even when the user already closed the channel explicitly.

NOTE: the resumed coroutines run during this destructor. They must not start another operation on the channel. A receiver's await_resume only uses its own delivery slot, so completing a parked receive does not access the channel again.

Member Function Documentation

◆ operator=() [1/2]

template<typename T>
Channel & aria::async::Channel< T >::operator= ( const Channel< T > & )
delete

◆ operator=() [2/2]

template<typename T>
Channel & aria::async::Channel< T >::operator= ( Channel< T > && )
delete

◆ send()

template<typename T>
auto aria::async::Channel< T >::send ( T value)
inline

◆ recv()

template<typename T>
auto aria::async::Channel< T >::recv ( )
inline

◆ close()

template<typename T>
void aria::async::Channel< T >::close ( )
inline

Mark the channel closed and release EVERY parked coroutine.

Still-parked receivers observe an empty optional (end of stream). Values already buffered or assigned to a receiver are not discarded. Senders parked on a full buffer are woken too and their pending values are dropped — matching send()'s own "channel already closed → drop the value and continue" behaviour. Waking only the receivers (the original implementation) left every blocked sender suspended forever, leaking one coroutine frame each and hanging any producer that was waiting for buffer space at close time.

◆ is_closed()

template<typename T>
bool aria::async::Channel< T >::is_closed ( ) const
inlinenodiscard

◆ size()

template<typename T>
std::size_t aria::async::Channel< T >::size ( ) const
inlinenodiscard

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