| 1 |
// Copyright 2021 gRPC authors. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
#ifndef GRPC_CORE_LIB_PROMISE_JOIN_H |
| 16 |
#define GRPC_CORE_LIB_PROMISE_JOIN_H |
| 17 |
|
| 18 |
#include <grpc/support/port_platform.h> |
| 19 |
|
| 20 |
#include "absl/meta/type_traits.h" |
| 21 |
|
| 22 |
#include "src/core/lib/promise/detail/basic_join.h" |
| 23 |
|
| 24 |
namespace grpc_core { |
| 25 |
namespace promise_detail { |
| 26 |
|
| 27 |
struct JoinTraits { |
| 28 |
template <typename T> |
| 29 |
using ResultType = absl::remove_reference_t<T>; |
| 30 |
template <typename T, typename F> |
| 31 |
static auto OnResult(T result, F kontinue) |
| 32 |
-> decltype(kontinue(std::move(result))) { |
| 33 |
return kontinue(std::move(result)); |
| 34 |
} |
| 35 |
template <typename T> |
| 36 |
static T Wrap(T x) { |
| 37 |
return x; |
| 38 |
} |
| 39 |
}; |
| 40 |
|
| 41 |
template <typename... Promises> |
| 42 |
using Join = BasicJoin<JoinTraits, Promises...>; |
| 43 |
|
| 44 |
} // namespace promise_detail |
| 45 |
|
| 46 |
/// Combinator to run all promises to completion, and return a tuple |
| 47 |
/// of their results. |
| 48 |
template <typename... Promise> |
| 49 |
promise_detail::Join<Promise...> Join(Promise... promises) { |
| 50 |
return promise_detail::Join<Promise...>(std::move(promises)...); |
| 51 |
} |
| 52 |
|
| 53 |
} // namespace grpc_core |
| 54 |
|
| 55 |
#endif // GRPC_CORE_LIB_PROMISE_JOIN_H |