22#include "util/Assert.hpp"
23#include "util/async/Concepts.hpp"
25#include <boost/asio/spawn.hpp>
45 template <SomeStopToken TokenType>
48 : pimpl_{std::make_unique<Model<TokenType>>(std::forward<TokenType>(token))}
63 pimpl_.swap(copy.pimpl_);
81 return pimpl_->isStopRequested();
89 [[nodiscard]]
operator bool() const noexcept
100 [[nodiscard]]
operator boost::asio::yield_context()
const
102 return pimpl_->yieldContext();
107 virtual ~Concept() =
default;
109 [[nodiscard]]
virtual bool
110 isStopRequested() const noexcept = 0;
112 [[nodiscard]] virtual std::unique_ptr<Concept>
116 yieldContext() const = 0;
120 struct Model : Concept {
123 Model(TokenType&& token) : token{std::move(token)}
128 isStopRequested() const noexcept
override
130 return token.isStopRequested();
133 [[nodiscard]] std::unique_ptr<Concept>
134 clone()
const override
136 return std::make_unique<Model>(*
this);
139 [[nodiscard]] boost::asio::yield_context
140 yieldContext()
const override
142 if constexpr (std::is_convertible_v<TokenType, boost::asio::yield_context>) {
146 ASSERT(
false,
"Token type does not support conversion to boost::asio::yield_context");
152 std::unique_ptr<Concept> pimpl_;
A type-erased stop token.
Definition AnyStopToken.hpp:37
bool isStopRequested() const noexcept
Check if stop is requested.
Definition AnyStopToken.hpp:79
operator boost::asio::yield_context() const
Get the underlying boost::asio::yield_context.
Definition AnyStopToken.hpp:100
AnyStopToken(TokenType &&token)
Construct a new type-erased Stop Token object.
Definition AnyStopToken.hpp:47
Checks that decayed T s not of the same type as Erased.
Definition Concepts.hpp:190
Specifies the interface for a stop token.
Definition Concepts.hpp:102
This namespace implements an async framework built on top of execution contexts.
Definition AnyExecutionContext.hpp:36