YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
wait.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <
yaclib/async/detail/wait_impl.hpp
>
4
#include <
yaclib/async/future.hpp
>
5
#include <yaclib/config.hpp>
6
#include <
yaclib/util/detail/default_event.hpp
>
7
8
#include <cstddef>
9
10
namespace
yaclib
{
11
12
/**
13
* Wait until \ref Ready becomes true
14
*
15
* \param fs one or more futures to wait
16
*/
17
template
<
typename
Event
=
detail::DefaultEvent
,
typename
...
Waited
>
18
YACLIB_INLINE
std::enable_if_t<(... &&
is_waitable_v<Waited>
),
void
>
Wait
(
Waited
&...
fs
)
noexcept
{
19
YACLIB_ASSERT
(... &&
fs
.Valid());
20
detail::WaitCore<Event>(
detail::NoTimeoutTag
{},
fs
.GetHandle()...);
21
}
22
23
/**
24
* Wait until \ref Ready becomes true
25
*
26
* \param begin iterator to futures to wait
27
* \param end iterator to futures to wait
28
*/
29
template
<
typename
Event
=
detail::DefaultEvent
,
typename
It,
typename
Sentinel
,
30
typename
= std::enable_if_t<is_input_range_pair_v<It, Sentinel> &&
31
is_waitable_v<typename std::iterator_traits<It>::reference
>>>
32
YACLIB_INLINE
void
Wait
(It
begin
,
Sentinel
end
)
noexcept
{
33
static_assert
(
34
has_constant_time_distance_v<It, Sentinel>
,
35
"Use Wait(begin, std::distance(begin, end)) instead"
);
// We don't use std::distance because we want to alert
36
// the user to the fact that it can be expensive.
37
38
Wait<Event>
(
begin
,
static_cast<
std::size_t
>
(
end
-
begin
));
39
}
40
41
/**
42
* Wait until \ref Ready becomes true
43
*
44
* \param range of futures to wait
45
*/
46
template
<
47
typename
Event
=
detail::DefaultEvent
,
typename
Range
,
48
typename
= std::enable_if_t<is_input_range_v<Range> &&
49
is_waitable_v<typename std::iterator_traits<detail::RangeIterator<Range>
>::reference>>>
50
YACLIB_INLINE
void
Wait
(
Range
&&
range
)
noexcept
{
51
Wait<Event>
(std::begin(
range
), std::end(
range
));
52
}
53
54
/**
55
* Wait until \ref Ready becomes true
56
*
57
* \param begin iterator to futures to wait
58
* \param count of futures to wait
59
*/
60
template
<
61
typename
Event
=
detail::DefaultEvent
,
typename
It,
62
typename
= std::enable_if_t<is_input_iterator_v<It> &&
is_waitable_v<typename std::iterator_traits<It>::reference
>>>
63
YACLIB_INLINE
void
Wait
(It
begin
, std::size_t count)
noexcept
{
64
detail::WaitIterator<Event>(
detail::NoTimeoutTag
{},
begin
, count);
65
}
66
67
}
// namespace yaclib
future.hpp
Event
default_event.hpp
YACLIB_ASSERT
#define YACLIB_ASSERT(cond)
Definition
log.hpp:85
yaclib::detail::DefaultEvent
MutexEvent DefaultEvent
Definition
default_event.hpp:16
yaclib
Definition
base_core.hpp:15
yaclib::MakeContract
Contract< V, T > MakeContract()
Creates related future and promise.
Definition
contract.hpp:25
yaclib::Wait
YACLIB_INLINE std::enable_if_t<(... &&is_waitable_v< Waited >), void > Wait(Waited &... fs) noexcept
Wait until Ready becomes true.
Definition
wait.hpp:18
yaclib::detail::NoTimeoutTag
Definition
wait_impl.hpp:17
wait_impl.hpp
include
yaclib
async
wait.hpp
Generated by
1.9.8