3#include "util/Assert.hpp"
4#include "util/async/Concepts.hpp"
6#include <boost/asio/spawn.hpp>
26 template <SomeStopToken TokenType>
29 : pimpl_{std::make_unique<Model<TokenType>>(std::forward<TokenType>(token))}
44 pimpl_.swap(copy.pimpl_);
62 return pimpl_->isStopRequested();
71 operator bool() const noexcept
83 operator boost::asio::yield_context()
const
85 return pimpl_->yieldContext();
90 virtual ~Concept() =
default;
92 [[nodiscard]]
virtual bool
95 [[nodiscard]] virtual std::unique_ptr<Concept>
99 yieldContext() const = 0;
103 struct Model : Concept {
106 Model(TokenType&& token) : token{std::move(token)}
113 return token.isStopRequested();
116 [[nodiscard]] std::unique_ptr<Concept>
117 clone()
const override
119 return std::make_unique<Model>(*
this);
122 [[nodiscard]] boost::asio::yield_context
123 yieldContext()
const override
125 if constexpr (std::is_convertible_v<TokenType, boost::asio::yield_context>) {
129 ASSERT(
false,
"Token type does not support conversion to boost::asio::yield_context");
135 std::unique_ptr<Concept> pimpl_;
A type-erased stop token.
Definition AnyStopToken.hpp:18
bool isStopRequested() const noexcept
Check if stop is requested.
Definition AnyStopToken.hpp:60
operator boost::asio::yield_context() const
Get the underlying boost::asio::yield_context.
Definition AnyStopToken.hpp:83
AnyStopToken(TokenType &&token)
Construct a new type-erased Stop Token object.
Definition AnyStopToken.hpp:28
Checks that decayed T s not of the same type as Erased.
Definition Concepts.hpp:202
Specifies the interface for a stop token.
Definition Concepts.hpp:113
This namespace implements an async framework built on top of execution contexts.
Definition AnyExecutionContext.hpp:17