44 std::reference_wrapper<ParentContextType> parentContext_;
45 typename ParentContextType::ContextHolderType::Strand context_;
49 static constexpr bool kIS_NOEXCEPT =
noexcept(ErrorHandlerType::wrap([](
auto&) {
throw 0; }));
51 using ContextHolderType =
typename ParentContextType::ContextHolderType::Strand;
52 using ExecutorType =
typename ContextHolderType::Executor;
53 using StopToken =
typename StopSourceType::Token;
55 typename ParentContextType::ContextHolderType::Timer;
58 BasicStrand(ParentContextType& parent,
auto&& strand)
59 : parentContext_{std::ref(parent)}, context_{std::forward<decltype(strand)>(strand)}
71 std::optional<std::chrono::milliseconds> timeout = std::nullopt
72 )
noexcept(kIS_NOEXCEPT)
74 return DispatcherType::dispatch(
76 impl::outcomeForHandler<StopSourceType>(fn),
77 ErrorHandlerType::wrap([
this, timeout, fn = std::forward<
decltype(fn)>(fn)](
78 auto& outcome,
auto& stopSource,
auto stopToken
80 [[maybe_unused]]
auto timeoutHandler = impl::getTimeoutHandleIfNeeded(
81 TimerContextProvider::getContext(parentContext_.get()), timeout, stopSource
84 using FnRetType = std::decay_t<decltype(fn(std::declval<StopToken>()))>;
85 if constexpr (std::is_void_v<FnRetType>) {
86 fn(std::move(stopToken));
89 outcome.setValue(fn(std::move(stopToken)));
99 std::forward<
decltype(fn)>(fn),
100 std::make_optional(std::chrono::duration_cast<std::chrono::milliseconds>(timeout))
107 return DispatcherType::dispatch(
109 impl::outcomeForHandler<StopSourceType>(fn),
110 ErrorHandlerType::wrap([fn = std::forward<
decltype(fn)>(fn)](
auto& outcome)
mutable {
111 using FnRetType = std::decay_t<
decltype(fn())>;
112 if constexpr (std::is_void_v<FnRetType>) {
116 outcome.setValue(fn());
125 if constexpr (not std::is_same_v<
decltype(TimerContextProvider::getContext(*
this)),
decltype(*this)>) {
126 return TimerContextProvider::getContext(*this).executeRepeatedly(interval, std::forward<
decltype(fn)>(fn));
128 return RepeatedOperation(impl::extractAssociatedExecutor(*
this), interval, std::forward<
decltype(fn)>(fn));