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
47getTimeoutHandleIfNeeded(
53 using TimerType =
typename CtxType::Timer;
54 std::optional<TimerType> timer;
56 timer.emplace(extractAssociatedExecutor(ctx), *timeout, [&stopSource](
auto cancelled) {
58 stopSource.requestStop();
64template <SomeStopSource StopSourceType>
65[[nodiscard]]
constexpr auto
66outcomeForHandler(
auto&& fn)
68 if constexpr (SomeHandlerWith<
decltype(fn),
typename StopSourceType::Token>) {
70 std::decay_t<std::invoke_result_t<
decltype(fn),
typename StopSourceType::Token>>;
71 using RetType = std::expected<FnRetType, ExecutionError>;
73 return StoppableOutcome<RetType, StopSourceType>();
75 using FnRetType = std::decay_t<std::invoke_result_t<
decltype(fn)>>;
76 using RetType = std::expected<FnRetType, ExecutionError>;
78 return Outcome<RetType>();
83 template <
typename CtxType>
84 [[nodiscard]]
static constexpr auto&
85 getContext(CtxType& self)
noexcept
Specifies that the type must be some std::duration wrapped in an optional.
Definition Concepts.hpp:215
Specifies the interface for a stop source.
Definition Concepts.hpp:156