22#include "util/async/Concepts.hpp"
23#include "util/async/Error.hpp"
24#include "util/async/context/impl/Timer.hpp"
26#include <boost/asio/spawn.hpp>
27#include <boost/asio/strand.hpp>
28#include <boost/asio/thread_pool.hpp>
33namespace util::async::impl {
36 template <
typename CtxType>
37 [[nodiscard]]
typename CtxType::ExecutorType&
38 operator()(CtxType& ctx)
const noexcept
40 return ctx.context_.getExecutor();
42} extractAssociatedExecutor;
44template <
typename CtxType>
45[[nodiscard]]
constexpr auto
48 using TimerType =
typename CtxType::Timer;
49 std::optional<TimerType> timer;
51 timer.emplace(extractAssociatedExecutor(ctx), *timeout, [&stopSource](
auto cancelled) {
53 stopSource.requestStop();
59template <SomeStopSource StopSourceType>
60[[nodiscard]]
constexpr auto
61outcomeForHandler(
auto&& fn)
63 if constexpr (SomeHandlerWith<
decltype(fn),
typename StopSourceType::Token>) {
64 using FnRetType =
decltype(fn(std::declval<typename StopSourceType::Token>()));
65 using RetType = std::expected<FnRetType, ExecutionError>;
67 return StoppableOutcome<RetType, StopSourceType>();
69 using FnRetType =
decltype(fn());
70 using RetType = std::expected<FnRetType, ExecutionError>;
72 return Outcome<RetType>();
77 template <
typename CtxType>
78 [[nodiscard]]
static constexpr auto&
79 getContext(CtxType& self)
noexcept
Specifies that the type must be some std::duration wrapped in an optional.
Definition Concepts.hpp:184
Specifies the interface for a stop source.
Definition Concepts.hpp:126