/
await_on.hpp
35 lines (29 loc) · 1.23 KB
/
await_on.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#pragma once
#include <yaclib/async/future.hpp>
#include <yaclib/coro/coro.hpp>
#include <yaclib/coro/detail/await_on_awaiter.hpp>
#include <yaclib/util/type_traits.hpp>
namespace yaclib {
template <typename... V, typename... E>
YACLIB_INLINE auto AwaitOn(IExecutor& e, FutureBase<V, E>&... fs) noexcept {
return detail::AwaitOnAwaiter<sizeof...(fs) == 1>{e, static_cast<detail::BaseCore&>(*fs.GetCore())...};
}
/**
* TODO(mkornaukhov03) Add doxygen docs
*/
template <typename Iterator>
YACLIB_INLINE auto AwaitOn(IExecutor& e, Iterator begin, std::size_t count) noexcept
-> std::enable_if_t<!is_future_base_v<Iterator>, detail::AwaitOnAwaiter<false>> {
return detail::AwaitOnAwaiter<false>{e, begin, count};
}
/**
* TODO(mkornaukhov03) Add doxygen docs
*/
template <typename BeginIt, typename EndIt>
YACLIB_INLINE auto AwaitOn(IExecutor& e, BeginIt begin, EndIt end) noexcept
-> std::enable_if_t<!is_future_base_v<BeginIt>, detail::AwaitOnAwaiter<false>> {
// We don't use std::distance because we want to alert the user to the fact that it can be expensive.
// Maybe the user has the size of the range, otherwise it is suggested to call Await(begin, distance(begin, end))
return AwaitOn(e, begin, end - begin);
}
} // namespace yaclib