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

Detailed Description

template<class T>
class thread::Reader< T >

A Reader is used to read items from a Channel.

You can get a pointer to a Reader by calling Channel<T>::reader(), which is the object that you should pass to code that needs to read from the channel.

#include <channel.h>

Public Member Functions

bool Read (T *absl_nonnull item)
 Reads an item from the channel, blocking until it can be read. Returns false if and only if the channel is closed.
 
Case OnRead (T *absl_nonnull item, bool *absl_nonnull ok)
 Returns a Case that can be used to wait for and synchronise on reading an item from the channel.
 

Member Function Documentation

◆ OnRead()

template<typename T>
Case thread::Reader< T >::OnRead ( T *absl_nonnull item,
bool *absl_nonnull ok )

Returns a Case that can be used to wait for and synchronise on reading an item from the channel.

Note
The item is only read out of the channel if the returned Case is selected. For example:
// `reader` is a thread::Reader<T> pointer from a channel
// with non-empty strings
std::string item;
bool ok;
const int selected = thread::Select({
thread::OnCancel(),
reader->OnRead(&item, &ok),
});
if (selected == 0) {
assert(!ok);
assert(item.empty());
}
int Select(const CaseArray &cases)
Returns the index of the first case that is ready, blocking until one is.
Definition select.h:75
Returns
True if an item was read from the channel, false if the channel was closed before or while reading.

◆ Read()

template<typename T>
bool thread::Reader< T >::Read ( T *absl_nonnull item)

Reads an item from the channel, blocking until it can be read. Returns false if and only if the channel is closed.

On returning true, the item is moved into the provided pointer.

Returns
True if an item was read from the channel, false if the channel was closed before or while reading.

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