9#include <userver/engine/deadline.hpp>
10#include <userver/engine/future_status.hpp>
11#include <userver/utils/meta.hpp>
12#include <userver/utils/span.hpp>
14USERVER_NAMESPACE_BEGIN
43template <
typename... Tasks>
49template <
typename... Tasks,
typename Rep,
typename Period>
51 const std::chrono::duration<Rep, Period>& duration, Tasks&... tasks);
56template <
typename... Tasks,
typename Clock,
typename Duration>
58 const std::chrono::time_point<Clock, Duration>& until, Tasks&... tasks);
63template <
typename... Tasks>
64[[nodiscard]]
FutureStatus WaitAllCheckedUntil(Deadline deadline,
71FutureStatus DoWaitAllChecked(utils::span<ContextAccessor*> targets,
74template <
typename Container>
75FutureStatus WaitAllCheckedFromContainer(Deadline deadline, Container& tasks) {
76 std::vector<ContextAccessor*> targets;
77 targets.reserve(std::size(tasks));
79 for (
auto& task : tasks) {
80 targets.push_back(task.TryGetContextAccessor());
83 return impl::DoWaitAllChecked(targets, deadline);
86template <
typename... Tasks>
87FutureStatus WaitAllCheckedFromTasks(Deadline deadline, Tasks&... tasks) {
88 ContextAccessor* targets[]{tasks.TryGetContextAccessor()...};
89 return impl::DoWaitAllChecked(targets, deadline);
100template <
typename... Tasks>
102 impl::HandleWaitAllStatus(engine::WaitAllCheckedUntil(Deadline
{}, tasks...));
105template <
typename... Tasks,
typename Rep,
typename Period>
107 const std::chrono::duration<Rep, Period>& duration, Tasks&... tasks) {
108 return WaitAllCheckedUntil(Deadline::FromDuration(duration), tasks...);
111template <
typename... Tasks,
typename Clock,
typename Duration>
113 const std::chrono::time_point<Clock, Duration>& until, Tasks&... tasks) {
114 return WaitAllCheckedUntil(Deadline::FromTimePoint(until), tasks...);
117template <
typename... Tasks>
118[[nodiscard]]
FutureStatus WaitAllCheckedUntil(Deadline deadline,
120 if constexpr (meta::impl::IsSingleRange<Tasks...>()) {
121 return impl::WaitAllCheckedFromContainer(deadline, tasks...);
123 return impl::WaitAllCheckedFromTasks(deadline, tasks...);