YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
await_on.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>>>
12 YACLIB_ASSERT(waited.Valid());
13 return detail::AwaitOnAwaiter{e, waited.GetHandle()};
14}
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 CoreEvent = AwaitOnEvent<false>;
21 using Event = std::conditional_t<kSharedCount == 0, CoreEvent, StaticSharedEvent<CoreEvent, kSharedCount>>;
22 YACLIB_ASSERT(... && waited.Valid());
23 return MultiAwaitOnAwaiter<Event>{e, waited.GetHandle()...};
24}
25
27 typename = std::enable_if_t<is_waitable_v<Value>>>
28YACLIB_INLINE auto AwaitOn(IExecutor& e, 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 CoreEvent = AwaitOnEvent<false>;
32 using Event = std::conditional_t<kShared, DynamicSharedEvent<CoreEvent>, CoreEvent>;
33 return MultiAwaitOnAwaiter<Event>{e, 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 AwaitOn(e, begin, static_cast<std::size_t>(end - begin));
42}
43
44} // namespace yaclib
#define YACLIB_ASSERT(cond)
Definition log.hpp:85
YACLIB_INLINE auto AwaitOn(IExecutor &e, Waited &waited) noexcept
Definition await_on.hpp:11
constexpr auto Count
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25