YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
await_inline.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <
yaclib/async/future.hpp
>
4
#include <
yaclib/coro/coro.hpp
>
5
#include <
yaclib/coro/detail/await_awaiter.hpp
>
6
#include <
yaclib/util/type_traits.hpp
>
7
8
namespace
yaclib
{
9
10
template
<
typename
Waited,
typename
= std::enable_if_t<is_waitable_v<Waited>>>
11
YACLIB_INLINE
auto
AwaitInline
(
Waited
&
waited
)
noexcept
{
12
YACLIB_ASSERT
(
waited
.Valid());
13
return
detail::AwaitAwaiter<typename Waited::Handle, false>
{
waited
.GetHandle()};
14
}
15
16
template
<
typename
...
Waited
,
typename
= std::enable_if_t<(... &&
is_waitable_v<Waited>
)>>
17
YACLIB_INLINE
auto
AwaitInline
(
Waited
&...
waited
)
noexcept
{
18
using namespace
detail;
19
static
constexpr
auto
kSharedCount
=
Count
<SharedHandle,
typename
Waited::Handle...>;
20
using
Awaiter
= std::conditional_t<kSharedCount == 0, MultiAwaitAwaiter<AwaitEvent<false>>,
21
MultiAwaitAwaiter<StaticSharedEvent<AwaitEvent<false>
,
kSharedCount
>>>;
22
YACLIB_ASSERT
(... &&
waited
.Valid());
23
return
Awaiter
{
waited
.GetHandle()...};
24
}
25
26
template <typename Iterator, typename Value = typename std::iterator_traits<Iterator>::value_type
,
27
typename
= std::enable_if_t<is_waitable_v<Value>>>
28
YACLIB_INLINE
auto
AwaitInline
(
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<false>>>,
32
MultiAwaitAwaiter<AwaitEvent<false>
>>;
33
return
Awaiter
{
begin
, count};
34
}
35
36
template
<
typename
Iterator
,
37
typename
= std::enable_if_t<is_waitable_v<typename std::iterator_traits<Iterator>::value_type>>>
38
YACLIB_INLINE
auto
AwaitInline
(
Iterator
begin
,
Iterator
end
)
noexcept
{
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
AwaitInline
(
begin
,
static_cast<
std::size_t
>
(
end
-
begin
));
42
}
43
44
}
// namespace yaclib
future.hpp
await_awaiter.hpp
coro.hpp
YACLIB_ASSERT
#define YACLIB_ASSERT(cond)
Definition
log.hpp:85
yaclib
Definition
base_core.hpp:15
yaclib::AwaitInline
YACLIB_INLINE auto AwaitInline(Waited &waited) noexcept
Definition
await_inline.hpp:11
yaclib::Count
constexpr auto Count
Definition
type_traits.hpp:86
yaclib::MakeContract
Contract< V, E > MakeContract()
Creates related future and promise.
Definition
contract.hpp:25
yaclib::detail::AwaitAwaiter
Definition
await_awaiter.hpp:88
type_traits.hpp
include
yaclib
coro
await_inline.hpp
Generated by
1.9.8