YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
wait.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <yaclib/config.hpp>
7
8#include <cstddef>
9
10namespace yaclib {
11
12/**
13 * Wait until \ref Ready becomes true
14 *
15 * \param fs one or more futures to wait
16 */
17template <typename Event = detail::DefaultEvent, typename... Waited>
18YACLIB_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.GetBaseHandle()...);
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 */
29template <typename Event = detail::DefaultEvent, typename It>
30YACLIB_INLINE std::enable_if_t<is_waitable_v<typename std::iterator_traits<It>::reference>, void> Wait(
31 It begin, It end) noexcept {
32 // We don't use std::distance because we want to alert the user to the fact that it can be expensive.
33 // Maybe the user has the size of the range, otherwise it is suggested to call Wait*(..., begin, distance(begin, end))
34 detail::WaitIterator<Event>(detail::NoTimeoutTag{}, begin, static_cast<std::size_t>(end - begin));
35}
36
37/**
38 * Wait until \ref Ready becomes true
39 *
40 * \param begin iterator to futures to wait
41 * \param count of futures to wait
42 */
43template <typename Event = detail::DefaultEvent, typename It>
44YACLIB_INLINE std::enable_if_t<is_waitable_v<typename std::iterator_traits<It>::reference>, void> Wait(
45 It begin, std::size_t count) noexcept {
46 detail::WaitIterator<Event>(detail::NoTimeoutTag{}, begin, count);
47}
48
49} // namespace yaclib
#define YACLIB_ASSERT(cond)
Definition log.hpp:85
MutexEvent DefaultEvent
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25
YACLIB_INLINE std::enable_if_t<(... &&is_waitable_v< Waited >), void > Wait(Waited &... fs) noexcept
Wait until Ready becomes true.
Definition wait.hpp:18