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
3
#include <
yaclib/async/future.hpp
>
4
#include <
yaclib/coro/coro.hpp
>
5
#include <
yaclib/coro/detail/await_on_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
AwaitOn
(
IExecutor
&
e
,
Waited
&
waited
)
noexcept
{
12
YACLIB_ASSERT
(
waited
.Valid());
13
return
detail::AwaitOnAwaiter
{
e
,
waited
.GetHandle()};
14
}
15
16
template
<
typename
...
Waited
,
typename
= std::enable_if_t<(... &&
is_waitable_v<Waited>
)>>
17
YACLIB_INLINE
auto
AwaitOn
(
IExecutor
&
e
,
Waited
&...
waited
)
noexcept
{
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
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
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
36
template
<
typename
Iterator
,
37
typename
= std::enable_if_t<is_waitable_v<typename std::iterator_traits<Iterator>::value_type>>>
38
YACLIB_INLINE
auto
AwaitOn
(
IExecutor
&
e
,
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
AwaitOn
(
e
,
begin
,
static_cast<
std::size_t
>
(
end
-
begin
));
42
}
43
44
}
// namespace yaclib
future.hpp
await_on_awaiter.hpp
Event
yaclib::IExecutor
Definition
executor.hpp:8
coro.hpp
YACLIB_ASSERT
#define YACLIB_ASSERT(cond)
Definition
log.hpp:85
yaclib
Definition
base_core.hpp:15
yaclib::AwaitOn
YACLIB_INLINE auto AwaitOn(IExecutor &e, Waited &waited) noexcept
Definition
await_on.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::AwaitOnAwaiter
Definition
await_on_awaiter.hpp:59
type_traits.hpp
include
yaclib
coro
await_on.hpp
Generated by
1.9.8