A coroutine-based channel for sending and receiving messages asynchronously. More...
#include <channel.hpp>
Public Member Functions | |
| coro::task< bool > | send (Message msg) |
| Asynchronously send a message into the channel. More... | |
| coro::task< Message > | receive () |
| Asynchronously receive a message from the channel. More... | |
| coro::task< bool > | send_metadata (Message msg) |
| Asynchronously send a metadata message into the channel. More... | |
| coro::task< Message > | receive_metadata () |
| Asynchronously receive a metadata message from the channel. More... | |
| Actor | drain_metadata (std::shared_ptr< CoroThreadPoolExecutor > executor) |
| Drains all pending metadata messages from the channel and shuts down the metadata channel. More... | |
| Actor | drain (std::shared_ptr< CoroThreadPoolExecutor > executor) |
| Drains all pending messages from the channel and shuts it down. More... | |
| Actor | shutdown () |
| Immediately shuts down the channel. More... | |
| Actor | shutdown_metadata () |
| Immediately shuts down the metadata channel. More... | |
| bool | empty () const noexcept |
| Check whether the channel is empty. More... | |
| bool | is_shutdown () const noexcept |
| Check whether the channel is shut down. More... | |
A coroutine-based channel for sending and receiving messages asynchronously.
The constructor is private, use the factory method Context::create_channel() to create a new channel.
In addition to sending messages through a channel, channel producers can communicate metadata to consumers through a metadata side-channel.
Channel is bounded for the purposes of sending messages (via send), but the side-channel is unbounded for the purposes of sending metadata (via send_metadata). There is no implied ordering between metadata messages and ordinary messages (they travel over separate paths and do not interfere).Channel itself. For convenience, drain and shutdown ensure that both channel and metadata channel are shut down appropriately. One can also drain or shutdown the side-channel independently (drain_metadata and shutdown_metadata). Definition at line 52 of file channel.hpp.
| Actor rapidsmpf::streaming::Channel::drain | ( | std::shared_ptr< CoroThreadPoolExecutor > | executor | ) |
Drains all pending messages from the channel and shuts it down.
This is intended to ensure all remaining messages are processed.
shutdown_metadata (directly, or indirectly via shutdown) otherwise when the producer drains the output metadata channel it will block forever.| executor | The thread pool used to process remaining messages. |
| Actor rapidsmpf::streaming::Channel::drain_metadata | ( | std::shared_ptr< CoroThreadPoolExecutor > | executor | ) |
Drains all pending metadata messages from the channel and shuts down the metadata channel.
This is intended to ensure all remaining metadata messages are processed.
shutdown_metadata (directly, or indirectly via shutdown) otherwise when the producer drains the output metadata channel it will block forever.| executor | The thread pool used to process remaining messages. |
|
noexcept |
Check whether the channel is empty.
|
noexcept |
Check whether the channel is shut down.
| coro::task<Message> rapidsmpf::streaming::Channel::receive | ( | ) |
Asynchronously receive a message from the channel.
Suspends if the channel is empty.
| std::logic_error | If the received message is empty. |
| coro::task<Message> rapidsmpf::streaming::Channel::receive_metadata | ( | ) |
Asynchronously receive a metadata message from the channel.
Suspends if no metadata is available.
| coro::task<bool> rapidsmpf::streaming::Channel::send | ( | Message | msg | ) |
Asynchronously send a message into the channel.
Suspends if the channel is full.
| msg | The msg to send. |
| std::logic_error | If the message is empty. |
| coro::task<bool> rapidsmpf::streaming::Channel::send_metadata | ( | Message | msg | ) |
Asynchronously send a metadata message into the channel.
shutdown_metadata) before proceeding to send messages.| msg | The metadata message to send. |
| std::logic_error | If the message is empty. |
| Actor rapidsmpf::streaming::Channel::shutdown | ( | ) |
Immediately shuts down the channel.
Any pending or future send/receive operations (including metadata messages) will complete with failure.
| Actor rapidsmpf::streaming::Channel::shutdown_metadata | ( | ) |
Immediately shuts down the metadata channel.
Any pending or future metadata send/receive operations will complete with failure.
shutdown_metadata before anything else.