3#include "util/async/Concepts.hpp"
4#include "util/async/Error.hpp"
5#include "util/async/context/impl/Timer.hpp"
7#include <boost/asio/spawn.hpp>
8#include <boost/asio/strand.hpp>
9#include <boost/asio/thread_pool.hpp>
15namespace util::async::impl {
18 template <
typename CtxType>
19 [[nodiscard]]
typename CtxType::ExecutorType&
20 operator()(CtxType& ctx)
const noexcept
22 return ctx.context_.getExecutor();
24} extractAssociatedExecutor;
26template <
typename CtxType>
27[[nodiscard]]
constexpr auto
28getTimeoutHandleIfNeeded(
34 using TimerType =
typename CtxType::Timer;
35 std::optional<TimerType> timer;
37 timer.emplace(extractAssociatedExecutor(ctx), *timeout, [&stopSource](
auto cancelled) {
39 stopSource.requestStop();
45template <SomeStopSource StopSourceType>
46[[nodiscard]]
constexpr auto
47outcomeForHandler(
auto&& fn)
49 if constexpr (SomeHandlerWith<
decltype(fn),
typename StopSourceType::Token>) {
51 std::decay_t<std::invoke_result_t<
decltype(fn),
typename StopSourceType::Token>>;
52 using RetType = std::expected<FnRetType, ExecutionError>;
54 return StoppableOutcome<RetType, StopSourceType>();
56 using FnRetType = std::decay_t<std::invoke_result_t<
decltype(fn)>>;
57 using RetType = std::expected<FnRetType, ExecutionError>;
59 return Outcome<RetType>();
64 template <
typename CtxType>
65 [[nodiscard]]
static constexpr auto&
66 getContext(CtxType& self)
noexcept
Specifies that the type must be some std::duration wrapped in an optional.
Definition Concepts.hpp:196
Specifies the interface for a stop source.
Definition Concepts.hpp:137