6#include <yaclib/config.hpp>
17template <
typename Event = OneShotEvent>
45 return _event.Get(
order);
56 template <
bool NeedAdd =
true,
typename... V,
typename... T>
71 typename = std::enable_if_t<is_input_range_pair_v<It, Sentinel>>>
75 "Use Consume(begin, std::distance(begin, end)) instead");
89 template <
bool NeedAdd = true,
typename Range,
typename = std::enable_if_t<is_input_range_v<Range>>>
103 template <
bool NeedAdd = true,
typename It,
typename = std::enable_if_t<is_input_iterator_v<It>>>
116 template <
bool NeedAdd =
true,
typename... V,
typename... T>
131 typename = std::enable_if_t<is_input_range_pair_v<It, Sentinel>>>
135 "Use Attach(begin, std::distance(begin, end)) instead");
149 template <
bool NeedAdd = true,
typename Range,
typename = std::enable_if_t<is_input_range_v<Range>>>
163 template <
bool NeedAdd = true,
typename It,
typename = std::enable_if_t<is_input_iterator_v<It>>>
177 template <
typename Rep,
typename Period>
185 template <
typename Clock,
typename Duration>
195 return _event.AwaitInline();
202 return _event.AwaitSticky();
209 return _event.AwaitOn(
e);
232 _event.count.store(count, std::memory_order_relaxed);
238 static_assert(
sizeof...(cores) >= 1,
"Number of futures must be at least one");
239 static_assert((... && std::is_same_v<detail::BaseCore, Cores>),
240 "Futures must be Future in WaitGroup::Consume/Attach function");
242 return (... +
static_cast<std::size_t
>(
func(
cores)));
247 template <
bool NeedMove,
bool NeedAdd,
typename It>
250 "WaitGroup::Consume/Attach function Iterator must be point to some Future");
256 for (std::size_t
i = 0;
i != count; ++
i) {
269 template <
bool NeedMove,
bool NeedAdd,
typename Range>
270 void InsertRange(
const Range&
range, std::size_t count)
noexcept {
275 detail::UniqueHandle
handle{core};
277 if (
handle.SetCallback(_event.GetDrop())) {
283 return handle.SetCallback(_event.GetCall());
290 detail::MultiEvent<Event, detail::AtomicCounter, detail::CallCallback, detail::DropCallback> _event;
Provides a mechanism to access the result of async operations.
An object that allows you to Add some amount of async operations and then Wait for it to be Done.
YACLIB_INLINE void Reset(std::size_t count=0) noexcept
Reinitializes WaitGroup, semantically the same as *this = {};
YACLIB_INLINE void Wait() noexcept
TODO.
YACLIB_INLINE void Done(std::size_t count=1) noexcept
Done some Add-ed async operations.
YACLIB_INLINE void Add(std::size_t count=1) noexcept
Add some amount of async operations.
YACLIB_INLINE void Attach(It begin, Sentinel end) noexcept
Attach Future to WaitGroup with auto Done.
YACLIB_INLINE void Consume(It begin, std::size_t count) noexcept
Consume Future by WaitGroup with auto Done.
YACLIB_INLINE void Consume(FutureBase< V, T > &&... futures) noexcept
Consume Future by WaitGroup with auto Done.
YACLIB_INLINE std::size_t Count(std::memory_order order=std::memory_order_relaxed) const noexcept
YACLIB_INLINE bool WaitFor(const std::chrono::duration< Rep, Period > &timeout_duration)
TODO.
YACLIB_INLINE void Attach(Range &&range) noexcept
Attach Future to WaitGroup with auto Done.
WaitGroup(std::size_t count=0) noexcept
YACLIB_INLINE bool WaitUntil(const std::chrono::time_point< Clock, Duration > &timeout_time)
TODO.
YACLIB_INLINE void Consume(It begin, Sentinel end) noexcept
Consume Future by WaitGroup with auto Done.
YACLIB_INLINE void Attach(FutureBase< V, T > &... futures) noexcept
Attach Future to WaitGroup with auto Done.
YACLIB_INLINE void Attach(It begin, std::size_t count) noexcept
Attach Future to WaitGroup with auto Done.
YACLIB_INLINE void Consume(Range &&range) noexcept
Consume Future by WaitGroup with auto Done.
Contract< V, T > MakeContract()
Creates related future and promise.
YACLIB_INLINE auto AwaitInline(Waited &waited) noexcept
YACLIB_INLINE auto AwaitOn(IExecutor &e, Waited &waited) noexcept
YACLIB_INLINE auto AwaitSticky(Waited &waited) noexcept