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... V, typename... E>
19 YACLIB_ASSERT(... && fs.Valid());
20 detail::WaitCore<Event>(detail::NoTimeoutTag{}, UpCast<detail::BaseCore>(*fs.GetCore())...);
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_future_base_v<It>, void> Wait(It begin, It end) noexcept {
31 // We don't use std::distance because we want to alert the user to the fact that it can be expensive.
32 // Maybe the user has the size of the range, otherwise it is suggested to call Wait*(..., begin, distance(begin, end))
33 detail::WaitIterator<Event>(detail::NoTimeoutTag{}, begin, static_cast<std::size_t>(end - begin));
34}
35
36/**
37 * Wait until \ref Ready becomes true
38 *
39 * \param begin iterator to futures to wait
40 * \param count of futures to wait
41 */
42template <typename Event = detail::DefaultEvent, typename It>
43YACLIB_INLINE void Wait(It begin, std::size_t count) noexcept {
44 detail::WaitIterator<Event>(detail::NoTimeoutTag{}, begin, count);
45}
46
47} // namespace yaclib
Provides a mechanism to access the result of async operations.
Definition future.hpp:20
#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 void Wait(FutureBase< V, E > &... fs) noexcept
Wait until Ready becomes true.
Definition wait.hpp:18