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>
50[[nodiscard]]
FutureStatus WaitAllCheckedFor(
const std::chrono::duration<Rep, Period>& duration, Tasks&... tasks);
55template <
typename... Tasks,
typename Clock,
typename Duration>
56[[nodiscard]]
FutureStatus WaitAllCheckedUntil(
const std::chrono::time_point<Clock, Duration>& until, Tasks&... tasks);
61template <
typename... Tasks>
62[[nodiscard]]
FutureStatus WaitAllCheckedUntil(Deadline deadline, Tasks&... tasks);
68FutureStatus DoWaitAllChecked(
utils::span<ContextAccessor*> targets, Deadline deadline);
70template <
typename Container>
71FutureStatus WaitAllCheckedFromContainer(Deadline deadline, Container& tasks) {
72 std::vector<ContextAccessor*> targets;
73 targets.reserve(std::size(tasks));
75 for (
auto& task : tasks) {
76 targets.push_back(task.TryGetContextAccessor());
79 return impl::DoWaitAllChecked(targets, deadline);
82template <
typename... Tasks>
83FutureStatus WaitAllCheckedFromTasks(Deadline deadline, Tasks&... tasks) {
84 ContextAccessor* targets[]{tasks.TryGetContextAccessor()...};
85 return impl::DoWaitAllChecked(targets, deadline);
94template <
typename... Tasks>
96 impl::HandleWaitAllStatus(engine::WaitAllCheckedUntil(Deadline
{}, tasks...));
99template <
typename... Tasks,
typename Rep,
typename Period>
100[[nodiscard]]
FutureStatus WaitAllCheckedFor(
const std::chrono::duration<Rep, Period>& duration, Tasks&... tasks) {
101 return WaitAllCheckedUntil(Deadline::FromDuration(duration), tasks...);
104template <
typename... Tasks,
typename Clock,
typename Duration>
105[[nodiscard]]
FutureStatus WaitAllCheckedUntil(
const std::chrono::time_point<Clock, Duration>& until, Tasks&... tasks) {
106 return WaitAllCheckedUntil(Deadline::FromTimePoint(until), tasks...);
109template <
typename... Tasks>
110[[nodiscard]]
FutureStatus WaitAllCheckedUntil(Deadline deadline, Tasks&... tasks) {
111 if constexpr (meta::impl::IsSingleRange<Tasks...>()) {
112 return impl::WaitAllCheckedFromContainer(deadline, tasks...);
114 return impl::WaitAllCheckedFromTasks(deadline, tasks...);