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();
90 operator bool() const noexcept
102 operator boost::asio::yield_context()
const
104 return pimpl_->yieldContext();
109 virtual ~Concept() =
default;
111 [[nodiscard]]
virtual bool
112 isStopRequested() const noexcept = 0;
114 [[nodiscard]] virtual std::unique_ptr<Concept>
118 yieldContext() const = 0;
122 struct Model : Concept {
125 Model(TokenType&& token) : token{std::move(token)}
130 isStopRequested() const noexcept
override
132 return token.isStopRequested();
135 [[nodiscard]] std::unique_ptr<Concept>
136 clone()
const override
138 return std::make_unique<Model>(*
this);
141 [[nodiscard]] boost::asio::yield_context
142 yieldContext()
const override
144 if constexpr (std::is_convertible_v<TokenType, boost::asio::yield_context>) {
148 ASSERT(
false,
"Token type does not support conversion to boost::asio::yield_context");
154 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:102
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:198
Specifies the interface for a stop token.
Definition Concepts.hpp:110
This namespace implements an async framework built on top of execution contexts.
Definition AnyExecutionContext.hpp:36