A receiver which reads values from an asynchronous channel.
Public Member Functions | |
| Receiver (const Receiver &other)=delete | |
| Receiver & | operator= (const Receiver &other)=delete |
| Receiver (Receiver &&other) noexcept | |
| Receiver & | operator= (Receiver &&other) noexcept |
| Result< T > | BlockingReceive (Dispatcher &dispatcher, chrono::SystemClock::duration timeout=kWaitForever) |
| ReceiveFuture< T > | Receive () |
| Result< T > | TryReceive () |
| void | Disconnect () |
| bool | is_open () const |
| Returns true if the channel is open. | |
Friends | |
| template<typename U > | |
| class | internal::Channel |
| template<typename U > | |
| std::optional< std::tuple< MpscChannelHandle< U >, Receiver< U > > > | CreateMpscChannel (Allocator &, uint16_t) |
| template<typename U , uint16_t kCapacity> | |
| std::tuple< MpscChannelHandle< U >, Receiver< U > > | CreateMpscChannel (ChannelStorage< U, kCapacity > &storage) |
| template<typename U > | |
| std::optional< std::tuple< SpscChannelHandle< U >, Sender< U >, Receiver< U > > > | CreateSpscChannel (Allocator &, uint16_t) |
| template<typename U , uint16_t kCapacity> | |
| std::tuple< SpscChannelHandle< U >, Sender< U >, Receiver< U > > | CreateSpscChannel (ChannelStorage< U, kCapacity > &storage) |
|
inline |
Reads a value from the channel, blocking until it is available.
This operation blocks the running thread until it is complete. It must not be called from an async context, or it will likely deadlock.
|
inline |
Removes this receiver from its channel, preventing the receiver from reading further values.
The channel may remain open if other receivers exist.
|
inline |
Reads a value from the channel, blocking until it is available.
Returns a Future<std::optional<T>> which resolves to a T value if the read is successful, or std::nullopt if the channel is closed.
If there are multiple receivers for a channel, each of them compete for exclusive values.
|
inline |
Reads a value from the channel if one is available.
|
friend |
Creates a dynamically allocated multi-producer, single-consumer channel with a fixed storage capacity.
Returns a handle to the channel which may be used to create senders. After all desired senders are created, the handle can be dropped without affecting the channel.
All allocation occurs during the creation of the channel. After this function returns, usage of the channel is guaranteed not to allocate. If allocation fails, returns std::nullopt.
The channel remains open as long as at least either a handle, or at least one sender and one receiver exist.
|
friend |
Creates a dynamically allocated single-producer, single-consumer channel with a fixed storage capacity.
Returns a handle to the channel alongside the sender and receiver. The handle can be used to forcefully close the channel. If that is not required, it can be dropped without affecting the channel.
All allocation occurs during the creation of the channel. After this function returns, usage of the channel is guaranteed not to allocate. If allocation fails, returns std::nullopt.
The channel remains open as long as at least either a handle, or at least one sender and one receiver exist.