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>
34namespace util::async::impl {
37 template <
typename CtxType>
38 [[nodiscard]]
typename CtxType::ExecutorType&
39 operator()(CtxType& ctx)
const noexcept
41 return ctx.context_.getExecutor();
43} extractAssociatedExecutor;
45template <
typename CtxType>
46[[nodiscard]]
constexpr auto
49 using TimerType =
typename CtxType::Timer;
50 std::optional<TimerType> timer;
52 timer.emplace(extractAssociatedExecutor(ctx), *timeout, [&stopSource](
auto cancelled) {
54 stopSource.requestStop();
60template <SomeStopSource StopSourceType>
61[[nodiscard]]
constexpr auto
62outcomeForHandler(
auto&& fn)
64 if constexpr (SomeHandlerWith<
decltype(fn),
typename StopSourceType::Token>) {
65 using FnRetType = std::decay_t<std::invoke_result_t<
decltype(fn),
typename StopSourceType::Token>>;
66 using RetType = std::expected<FnRetType, ExecutionError>;
68 return StoppableOutcome<RetType, StopSourceType>();
70 using FnRetType = std::decay_t<std::invoke_result_t<
decltype(fn)>>;
71 using RetType = std::expected<FnRetType, ExecutionError>;
73 return Outcome<RetType>();
78 template <
typename CtxType>
79 [[nodiscard]]
static constexpr auto&
80 getContext(CtxType& self)
noexcept
Specifies that the type must be some std::duration wrapped in an optional.
Definition Concepts.hpp:192
Specifies the interface for a stop source.
Definition Concepts.hpp:134