25 std::reference_wrapper<ParentContextType> parentContext_;
26 typename ParentContextType::ContextHolderType::Strand context_;
27 friend AssociatedExecutorExtractor;
30 static constexpr bool kIS_NOEXCEPT =
noexcept(ErrorHandlerType::wrap([](
auto&) {
throw 0; }));
32 using ContextHolderType =
typename ParentContextType::ContextHolderType::Strand;
33 using ExecutorType =
typename ContextHolderType::Executor;
34 using StopToken =
typename StopSourceType::Token;
35 using Timer =
typename ParentContextType::ContextHolderType::Timer;
39 BasicStrand(ParentContextType& parent,
auto&& strand)
40 : parentContext_{std::ref(parent)}, context_{std::forward<decltype(strand)>(strand)}
44 ~BasicStrand() =
default;
45 BasicStrand(BasicStrand&&) =
default;
47 BasicStrand(BasicStrand
const&) =
delete;
52 std::optional<std::chrono::milliseconds> timeout = std::nullopt
53 )
noexcept(kIS_NOEXCEPT)
55 return DispatcherType::dispatch(
57 impl::outcomeForHandler<StopSourceType>(fn),
58 ErrorHandlerType::wrap([
this, timeout, fn = std::forward<
decltype(fn)>(fn)](
59 auto& outcome,
auto& stopSource,
auto stopToken
61 [[maybe_unused]]
auto timeoutHandler = impl::getTimeoutHandleIfNeeded(
62 TimerContextProvider::getContext(parentContext_.get()), timeout, stopSource
65 using FnRetType = std::decay_t<std::invoke_result_t<
decltype(fn), StopToken>>;
66 if constexpr (std::is_void_v<FnRetType>) {
67 std::invoke(std::forward<
decltype(fn)>(fn), std::move(stopToken));
71 std::invoke(std::forward<
decltype(fn)>(fn), std::move(stopToken))
84 std::forward<
decltype(fn)>(fn),
85 std::make_optional(std::chrono::duration_cast<std::chrono::milliseconds>(timeout))
92 return DispatcherType::dispatch(
94 impl::outcomeForHandler<StopSourceType>(fn),
95 ErrorHandlerType::wrap([fn = std::forward<
decltype(fn)>(fn)](
auto& outcome)
mutable {
96 using FnRetType = std::decay_t<std::invoke_result_t<
decltype(fn)>>;
97 if constexpr (std::is_void_v<FnRetType>) {
98 std::invoke(std::forward<
decltype(fn)>(fn));
101 outcome.setValue(std::invoke(std::forward<
decltype(fn)>(fn)));
111 )
noexcept(kIS_NOEXCEPT)
113 if constexpr (not std::is_same_v<
114 decltype(TimerContextProvider::getContext(*
this)),
116 return TimerContextProvider::getContext(*this).executeRepeatedly(
117 interval, std::forward<
decltype(fn)>(fn)
120 return RepeatedOperation(
121 impl::extractAssociatedExecutor(*
this), interval, std::forward<
decltype(fn)>(fn)
129 DispatcherType::post(context_, ErrorHandlerType::catchAndAssert(fn));