YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
await_sticky.hpp
Go to the documentation of this file.
1#pragma once
2
7
8namespace yaclib {
9
10template <typename Waited, typename = std::enable_if_t<is_waitable_v<Waited>>>
15
16template <typename... Waited, typename = std::enable_if_t<(... && is_waitable_v<Waited>)>>
18 using namespace detail;
19 static constexpr auto kSharedCount = Count<SharedHandle, typename Waited::Handle...>;
20 using Awaiter = std::conditional_t<kSharedCount == 0, MultiAwaitAwaiter<AwaitEvent<true>>,
22 YACLIB_ASSERT(... && waited.Valid());
23 return Awaiter{waited.GetHandle()...};
24}
25
27 typename = std::enable_if_t<is_waitable_v<Value>>>
28YACLIB_INLINE auto AwaitSticky(Iterator begin, std::size_t count) noexcept {
29 using namespace detail;
30 static constexpr auto kShared = std::is_same_v<typename Value::Handle, SharedHandle>;
31 using Awaiter = std::conditional_t<kShared, MultiAwaitAwaiter<DynamicSharedEvent<AwaitEvent<true>>>,
33 return Awaiter{begin, count};
34}
35
36template <typename Iterator,
37 typename = std::enable_if_t<is_waitable_v<typename std::iterator_traits<Iterator>::value_type>>>
39 // We don't use std::distance because we want to alert the user to the fact that it can be expensive.
40 // Maybe the user has the size of the range, otherwise it is suggested to call Await(begin, distance(begin, end))
41 return AwaitSticky(begin, static_cast<std::size_t>(end - begin));
42}
43
44} // namespace yaclib
#define YACLIB_ASSERT(cond)
Definition log.hpp:85
constexpr auto Count
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25
YACLIB_INLINE auto AwaitSticky(Waited &waited) noexcept