Action Engine
Loading...
Searching...
No Matches
thread::Channel< T > Class Template Reference

Detailed Description

template<typename T>
requires std::is_move_assignable_v<T>
class thread::Channel< T >

A Channel is a bounded FIFO queue that allows multiple readers and writers to communicate with each other.

The channel has a fixed capacity, and will block writers if the channel is full, and readers if the channel is empty. If the channel is closed, all waiting readers will be notified that no more items will be written to the channel.

#include <channel.h>

Public Member Functions

 Channel (size_t capacity)
 Constructs a Channel with the given capacity.
 
Reader< T > *absl_nonnull reader ()
 
Writer< T > *absl_nonnull writer ()
 
size_t length () const
 

Constructor & Destructor Documentation

◆ Channel()

template<typename T>
thread::Channel< T >::Channel ( size_t capacity)
inlineexplicit

Constructs a Channel with the given capacity.

Parameters
capacityThe maximum number of items that can be buffered in the channel. If the channel is full, writers will block until space is available.

Member Function Documentation

◆ length()

template<typename T>
size_t thread::Channel< T >::length ( ) const
inlinenodiscard

Returns the instantaneous length of the channel.

This method should never be used to determine whether the channel is full or empty, as it may return a value that is not consistent with the state of the channel at the time of the call.

◆ reader()

template<typename T>
Reader< T > *absl_nonnull thread::Channel< T >::reader ( )
inline

Returns a Reader that can be used to read items from the channel.

Multiple consumers can read from the channel concurrently, and every item written to the channel will be read by exactly one reader.

Returns
A Reader that can be used to read items from the channel.

◆ writer()

template<typename T>
Writer< T > *absl_nonnull thread::Channel< T >::writer ( )
inline

Returns a Writer that can be used to write items to the channel.

Multiple producers can write to the channel concurrently, and every item written to the channel, if read at all, will be read by exactly one reader. If the channel is at capacity, writers will block until space is available in the channel.

Returns
A Writer that can be used to write items to the channel.

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