Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
uni20::async::ReadBuffer< T > Class Template Reference

RAII handle for reading the value from an Async container at a given epoch. More...

#include <buffers.hpp>

Public Types

using value_type = T
 

Public Member Functions

bool await_ready () const noexcept
 Check if the value is already ready to be read.
 
OwningReadAccessProxy< T > await_resume () &&
 Resume execution and return an owning read proxy.
 
T const & await_resume () const &
 Resume execution and return the stored value.
 
void await_suspend (BasicTask &&t) noexcept
 Suspend this coroutine and enqueue for resumption.
 
std::shared_ptr< EpochContext > epoch_context_shared () const noexcept
 Returns the epoch context used for exception propagation.
 
T const & get_wait () const
 Block until the read value is available.
 
T const & get_wait (IAsyncScheduler &sched) const
 Block using an explicit scheduler until the read value is available.
 
ReadMaybeAwaiter< T const & > maybe () &
 Returns a ReadMaybeAwaiter.
 
ReadMaybeAwaiter< T > maybe () &&
 Returns a ReadMaybeAwaiter consuming this read buffer.
 
auto operator co_await () &&noexcept -> OwningReadAwaiter< T >
 Enable co_await on rvalue ReadBuffer and transfer ownership to an owning read proxy.
 
auto operator co_await () &noexcept -> ReadBuffer &
 Enable co_await on lvalue ReadBuffer and return a borrowed reference.
 
auto operator co_await () const &noexcept -> ReadBuffer const &
 
ReadBuffer & operator= (ReadBuffer &&other) noexcept
 Move assignment.
 
ReadBuffer & operator= (ReadBuffer const &)=delete
 
ReadOrCancelAwaiter< T const & > or_cancel () &
 Returns a ReadOrCancelAwaiter.
 
ReadOrCancelAwaiter< T > or_cancel () &&
 Returns a ReadOrCancelAwaiter consuming this read buffer.
 
 ReadBuffer (EpochContextReader< T > reader)
 Construct a read buffer tied to a reader context.
 
 ReadBuffer (ReadBuffer &&other) noexcept
 Move constructor.
 
 ReadBuffer (ReadBuffer const &other)
 Copy constructor; duplicates read handle and exception sink registration.
 
void register_exception_sink (TaskPromiseBase &promise, bool explicit_sink) const
 Register this buffer as an exception sink with a promise.
 
void release () noexcept
 Manually release the epoch reader before awaitable destruction.
 
ReadBuffer && transfer () &&noexcept
 Transfer this read buffer into the owning-await path.
 
ReadBuffer && transfer () &noexcept
 Transfer this read buffer into the owning-await path.
 
void wait () const
 Block until the read value is available.
 
void wait (IAsyncScheduler &sched) const
 Block using an explicit scheduler until the read value is available.
 
 ~ReadBuffer () noexcept
 Destructor unregisters any attached exception sink.
 

Detailed Description

template<typename T>
class uni20::async::ReadBuffer< T >

RAII handle for reading the value from an Async container at a given epoch.

A ReadBuffer<T> represents a read-only access to the value of an Async<T> at a specific epoch. It is awaitable, and yields either a borrowed reference or an owning proxy depending on value category:

Note
transfer() is the explicit owning form for named buffers. Direct co_await on a temporary buffer still uses the owning rvalue path.
A ReadBuffer<T> can be co_awaited multiple times, but buf.transfer() transfers ownership semantics and should only be used once. After moving, further use is undefined.
Template Parameters
TThe underlying value type.

Member Typedef Documentation

◆ value_type

template<typename T >
using uni20::async::ReadBuffer< T >::value_type = T

Constructor & Destructor Documentation

◆ ReadBuffer() [1/3]

template<typename T >
uni20::async::ReadBuffer< T >::ReadBuffer ( EpochContextReader< T >  reader)
inline

Construct a read buffer tied to a reader context.

Parameters
readerThe RAII epoch reader handle for this operation.

◆ ReadBuffer() [2/3]

template<typename T >
uni20::async::ReadBuffer< T >::ReadBuffer ( ReadBuffer< T > const &  other)
inline

Copy constructor; duplicates read handle and exception sink registration.

Parameters
otherSource read buffer.

◆ ReadBuffer() [3/3]

template<typename T >
uni20::async::ReadBuffer< T >::ReadBuffer ( ReadBuffer< T > &&  other)
inlinenoexcept

Move constructor.

Parameters
otherSource read buffer.

◆ ~ReadBuffer()

template<typename T >
uni20::async::ReadBuffer< T >::~ReadBuffer ( )
inlinenoexcept

Destructor unregisters any attached exception sink.

Member Function Documentation

◆ await_ready()

template<typename T >
bool uni20::async::ReadBuffer< T >::await_ready ( ) const
inlinenoexcept

Check if the value is already ready to be read.

Returns
True if the epoch is ready and no suspension is needed.

◆ await_resume() [1/2]

template<typename T >
OwningReadAccessProxy< T > uni20::async::ReadBuffer< T >::await_resume ( ) &&

Resume execution and return an owning read proxy.

◆ await_resume() [2/2]

template<typename T >
T const & uni20::async::ReadBuffer< T >::await_resume ( ) const &
inline

Resume execution and return the stored value.

Returns
Reference to the stored T inside Async<T>.

◆ await_suspend()

template<typename T >
void uni20::async::ReadBuffer< T >::await_suspend ( BasicTask &&  t)
inlinenoexcept

Suspend this coroutine and enqueue for resumption.

Parameters
tCoroutine task to enqueue.

◆ epoch_context_shared()

template<typename T >
std::shared_ptr< EpochContext > uni20::async::ReadBuffer< T >::epoch_context_shared ( ) const
inlinenoexcept

Returns the epoch context used for exception propagation.

Returns
Shared pointer to the epoch context.

◆ get_wait() [1/2]

template<typename T >
T const & uni20::async::ReadBuffer< T >::get_wait ( ) const
inline

Block until the read value is available.

Returns
Const reference to the available value.

◆ get_wait() [2/2]

template<typename T >
T const & uni20::async::ReadBuffer< T >::get_wait ( IAsyncScheduler &  sched) const
inline

Block using an explicit scheduler until the read value is available.

Parameters
schedScheduler used to drive progress.
Returns
Const reference to the available value.

◆ maybe() [1/2]

template<typename T >
ReadMaybeAwaiter< T const & > uni20::async::ReadBuffer< T >::maybe ( ) &

Returns a ReadMaybeAwaiter.

Lvalue reads return T const*; moved reads return std::optional<OwningReadAccessProxy<T>>.

◆ maybe() [2/2]

template<typename T >
ReadMaybeAwaiter< T > uni20::async::ReadBuffer< T >::maybe ( ) &&

Returns a ReadMaybeAwaiter consuming this read buffer.

Build a maybe-awaiter from an rvalue read buffer.

Moved reads return std::optional<OwningReadAccessProxy<T>>.

Template Parameters
TStored value type.
Returns
Awaiter yielding optional owning read access.

◆ operator co_await() [1/3]

template<typename T >
auto uni20::async::ReadBuffer< T >::operator co_await ( ) && -> OwningReadAwaiter<T>
inlinenoexcept

Enable co_await on rvalue ReadBuffer and transfer ownership to an owning read proxy.

◆ operator co_await() [2/3]

template<typename T >
auto uni20::async::ReadBuffer< T >::operator co_await ( ) & -> ReadBuffer&
inlinenoexcept

Enable co_await on lvalue ReadBuffer and return a borrowed reference.

◆ operator co_await() [3/3]

template<typename T >
auto uni20::async::ReadBuffer< T >::operator co_await ( ) const & -> ReadBuffer const&
inlinenoexcept

◆ operator=() [1/2]

template<typename T >
ReadBuffer & uni20::async::ReadBuffer< T >::operator= ( ReadBuffer< T > &&  other)
inlinenoexcept

Move assignment.

Parameters
otherSource read buffer.
Returns
Reference to *this.

◆ operator=() [2/2]

template<typename T >
ReadBuffer & uni20::async::ReadBuffer< T >::operator= ( ReadBuffer< T > const &  )
delete

◆ or_cancel() [1/2]

template<typename T >
ReadOrCancelAwaiter< T const & > uni20::async::ReadBuffer< T >::or_cancel ( ) &

Returns a ReadOrCancelAwaiter.

Lvalue reads return T const& and throw task_cancelled when no value was written. Exceptions stored by a failed writer propagate unchanged.

◆ or_cancel() [2/2]

template<typename T >
ReadOrCancelAwaiter< T > uni20::async::ReadBuffer< T >::or_cancel ( ) &&

Returns a ReadOrCancelAwaiter consuming this read buffer.

Build an or-cancel awaiter from an rvalue read buffer.

Moved reads return OwningReadAccessProxy<T> and throw task_cancelled when no value was written. Exceptions stored by a failed writer propagate unchanged.

Template Parameters
TStored value type.
Returns
Awaiter yielding owning read access or throwing on cancellation.

◆ register_exception_sink()

template<typename T >
void uni20::async::ReadBuffer< T >::register_exception_sink ( TaskPromiseBase &  promise,
bool  explicit_sink 
) const
inline

Register this buffer as an exception sink with a promise.

Parameters
promisePromise that owns the sink list.
explicit_sinkWhether this sink came from propagate_exceptions_to.

◆ release()

template<typename T >
void uni20::async::ReadBuffer< T >::release ( )
inlinenoexcept

Manually release the epoch reader before awaitable destruction.

This allows the coroutine to relinquish its reader role earlier than its full lifetime.

Postcondition
The ReadBuffer becomes inert and idempotent; calling release() more than once has no effect.

◆ transfer() [1/2]

template<typename T >
ReadBuffer && uni20::async::ReadBuffer< T >::transfer ( ) &&
inlinenoexcept

Transfer this read buffer into the owning-await path.

Returns
Rvalue reference to *this.

◆ transfer() [2/2]

template<typename T >
ReadBuffer && uni20::async::ReadBuffer< T >::transfer ( ) &
inlinenoexcept

Transfer this read buffer into the owning-await path.

Returns
Rvalue reference to *this.

◆ wait() [1/2]

template<typename T >
void uni20::async::ReadBuffer< T >::wait ( ) const
inline

Block until the read value is available.

◆ wait() [2/2]

template<typename T >
void uni20::async::ReadBuffer< T >::wait ( IAsyncScheduler &  sched) const
inline

Block using an explicit scheduler until the read value is available.

Parameters
schedScheduler used to drive progress.

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