YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
await.hpp
Go to the documentation of this file.
1#pragma once
2
8
9namespace yaclib {
10
11template <typename V, typename T>
16
17template <typename Waited, typename = std::enable_if_t<is_waitable_v<Waited>>>
19 return AwaitInline(waited);
20}
21
22template <typename... Waited, typename = std::enable_if_t<(... && is_waitable_v<Waited>)>>
23YACLIB_INLINE auto Await(Waited&... waited) noexcept {
24 return AwaitInline(waited...);
25}
26
27template <typename It, typename = std::enable_if_t<is_input_iterator_v<It> &&
28 is_waitable_v<typename std::iterator_traits<It>::value_type>>>
29YACLIB_INLINE auto Await(It begin, std::size_t count) noexcept {
30 return AwaitInline(begin, count);
31}
32
33template <typename It, typename Sentinel,
34 typename = std::enable_if_t<is_input_range_pair_v<It, Sentinel> &&
36YACLIB_INLINE auto Await(It begin, Sentinel end) noexcept {
37 static_assert(
39 "Use Await(begin, std::distance(begin, end)) instead"); // We don't use std::distance because we want to alert
40 // the user to the fact that it can be expensive.
41
42 return Await(begin, static_cast<std::size_t>(end - begin));
43}
44
45template <typename Range, typename = std::enable_if_t<
48YACLIB_INLINE auto Await(Range&& range) noexcept {
49 return Await(std::begin(range), std::end(range));
50}
51
52template <typename V, typename T>
53YACLIB_INLINE auto operator co_await(FutureBase<V, T>&& future) noexcept {
54 YACLIB_ASSERT(future.Valid());
55 return detail::AwaitSingleAwaiter<false, V, T>{std::move(future.GetCore())};
56}
57
58template <typename V, typename T>
59YACLIB_INLINE auto operator co_await(const SharedFutureBase<V, T>& future) noexcept {
60 YACLIB_ASSERT(future.Valid());
62}
63
64template <typename V, typename T>
65YACLIB_INLINE auto operator co_await(Task<V, T>&& task) noexcept {
66 YACLIB_ASSERT(task.Valid());
67 return detail::TransferSingleAwaiter{std::move(task.GetCore())};
68}
69
70} // namespace yaclib
Provides a mechanism to access the result of async operations.
Definition future.hpp:21
Provides a mechanism to schedule the some async operations TODO(MBkkt) add description.
Definition task.hpp:26
#define YACLIB_ASSERT(cond)
Definition log.hpp:85
Contract< V, T > MakeContract()
Creates related future and promise.
Definition contract.hpp:25
YACLIB_INLINE auto AwaitInline(Waited &waited) noexcept
YACLIB_INLINE auto Await(Task< V, T > &task) noexcept
Definition await.hpp:12