Helper RAII class to shut down channels when they go out of scope. More...
#include <channel.hpp>
Public Member Functions | |
| ShutdownAtExit (std::vector< std::shared_ptr< Channel >> channels) | |
| Construct from a vector of channel handles. More... | |
| template<class... T> | |
| ShutdownAtExit (T &&... channels) requires(std | |
| Variadic convenience constructor. More... | |
| ShutdownAtExit (ShutdownAtExit const &)=delete | |
| ShutdownAtExit & | operator= (ShutdownAtExit const &)=delete |
| ShutdownAtExit (ShutdownAtExit &&)=delete | |
| ShutdownAtExit & | operator= (ShutdownAtExit &&)=delete |
| ~ShutdownAtExit () noexcept | |
| Destructor that synchronously shuts down all channels. More... | |
Helper RAII class to shut down channels when they go out of scope.
When this object is destroyed, it invokes shutdown() on all provided channels in the order they were provided. After shutdown, any pending or future send/receive operations on those channels will fail or yield nullopt.
This is useful inside coroutine bodies to guarantee channels are shut down if an unhandled exception escapes the coroutine. Relying on a channel's own destructor is insufficient when the channel is shared (e.g., via std::shared_ptr), because other owners keep it alive.
Definition at line 262 of file channel.hpp.
|
inlineexplicit |
Construct from a vector of channel handles.
The order of elements determines the shutdown order invoked by the destructor.
| channels | Vector of shared channel handles to be shut down on destruction. |
| std::invalid_argument | If any channel in the vector is nullptr. |
Definition at line 273 of file channel.hpp.
|
inlineexplicit |
Variadic convenience constructor.
Enables ShutdownAtExit{ch1, ch2, ...} without explicitly creating a vector. Each argument must be convertible to std::shared_ptr<Channel>. The order of the arguments determines the shutdown order in the destructor.
| T | Parameter pack of types convertible to std::shared_ptr<Channel>. |
| channels | One or more channel handles. |
| std::invalid_argument | If any of the provided channel pointers is nullptr. |
Definition at line 293 of file channel.hpp.
|
inlinenoexcept |
Destructor that synchronously shuts down all channels.
Calls shutdown() on each channel in the same order they were passed.
Definition at line 310 of file channel.hpp.