9#include <userver/engine/wait_all_checked.hpp>
10#include <userver/utils/meta.hpp>
12USERVER_NAMESPACE_BEGIN
41template <
typename... Tasks>
42auto GetAll(Tasks&... tasks);
46template <
typename Container>
47auto GetAllResultsFromContainer(Container& tasks) {
48 using Result =
decltype(std::begin(tasks)->Get());
50 if constexpr (std::is_void_v<Result>) {
51 for (
auto& task : tasks) {
56 std::vector<Result> results;
57 results.reserve(std::size(tasks));
58 for (
auto& task : tasks) {
59 results.push_back(task.Get());
65template <
typename... Tasks>
66auto GetAllResultsFromTasks(Tasks&... tasks) {
67 using Result =
decltype((
void(), ..., tasks.Get()));
69 if constexpr (std::is_void_v<Result>) {
70 static_assert((
true && ... && std::is_void_v<
decltype(tasks.Get())>));
74 std::vector<Result> results;
75 results.reserve(
sizeof...(tasks));
76 (results.push_back(tasks.Get()), ...);
83template <
typename... Tasks>
85 engine::WaitAllChecked(tasks...);
86 if constexpr (meta::impl::IsSingleRange<Tasks...>()) {
87 return impl::GetAllResultsFromContainer(tasks...);
89 return impl::GetAllResultsFromTasks(tasks...);