YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
await.hpp
Go to the documentation of this file.
1#pragma once
2
7
8namespace yaclib {
9
10/**
11 * TODO(mkornaukhov03) Add doxygen docs
12 */
13template <typename V, typename E>
18
19/**
20 * TODO(mkornaukhov03) Add doxygen docs
21 */
22template <typename... V, typename... E>
24 YACLIB_ASSERT(... && fs.Valid());
25 return detail::AwaitAwaiter<sizeof...(fs) == 1>{UpCast<detail::BaseCore>(*fs.GetCore())...};
26}
27
28/**
29 * TODO(mkornaukhov03) Add doxygen docs
30 */
31template <typename Iterator>
32YACLIB_INLINE auto Await(Iterator begin, std::size_t count) noexcept
33 -> std::enable_if_t<!is_future_base_v<Iterator>, detail::AwaitAwaiter<false>> {
35}
36
37/**
38 * TODO(mkornaukhov03) Add doxygen docs
39 */
40template <typename Iterator>
42 -> std::enable_if_t<!is_future_base_v<Iterator>, detail::AwaitAwaiter<false>> {
43 // We don't use std::distance because we want to alert the user to the fact that it can be expensive.
44 // Maybe the user has the size of the range, otherwise it is suggested to call Await(begin, distance(begin, end))
45 return Await(begin, static_cast<std::size_t>(end - begin));
46}
47
48template <typename V, typename E>
49YACLIB_INLINE auto operator co_await(FutureBase<V, E>&& future) noexcept {
50 YACLIB_ASSERT(future.Valid());
51 return detail::AwaitSingleAwaiter{std::move(future.GetCore())};
52}
53
54template <typename V, typename E>
55YACLIB_INLINE auto operator co_await(Task<V, E>&& task) noexcept {
56 YACLIB_ASSERT(task.Valid());
57 return detail::TransferSingleAwaiter{std::move(task.GetCore())};
58}
59
60} // namespace yaclib
Provides a mechanism to access the result of async operations.
Definition future.hpp:20
Provides a mechanism to schedule the some async operations TODO(MBkkt) add description.
Definition task.hpp:25
#define YACLIB_ASSERT(cond)
Definition log.hpp:85
YACLIB_INLINE auto Await(Task< V, E > &task) noexcept
TODO(mkornaukhov03) Add doxygen docs.
Definition await.hpp:14
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25
TODO(mkornaukhov03) Add doxygen docs.