seq.h
Go to the documentation of this file.
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_SEQ_H
16 #define GRPC_CORE_LIB_PROMISE_SEQ_H
17 
19 
20 #include <utility>
21 
24 
25 namespace grpc_core {
26 
27 namespace promise_detail {
28 
29 template <typename T>
30 struct SeqTraits {
31  using UnwrappedType = T;
32  using WrappedType = T;
33  template <typename Next>
34  static auto CallFactory(Next* next, T&& value)
35  -> decltype(next->Once(std::forward<T>(value))) {
36  return next->Once(std::forward<T>(value));
37  }
38  template <typename F, typename Elem>
39  static auto CallSeqFactory(F& f, Elem&& elem, T&& value)
40  -> decltype(f(std::forward<Elem>(elem), std::forward<T>(value))) {
41  return f(std::forward<Elem>(elem), std::forward<T>(value));
42  }
43  template <typename Result, typename PriorResult, typename RunNext>
44  static Poll<Result> CheckResultAndRunNext(PriorResult prior,
45  RunNext run_next) {
46  return run_next(std::move(prior));
47  }
48 };
49 
50 template <typename... Fs>
51 using Seq = BasicSeq<SeqTraits, Fs...>;
52 
53 } // namespace promise_detail
54 
55 // Sequencing combinator.
56 // Run the first promise.
57 // Pass its result to the second, and run the returned promise.
58 // Pass its result to the third, and run the returned promise.
59 // etc
60 // Return the final value.
61 template <typename... Functors>
62 promise_detail::Seq<Functors...> Seq(Functors... functors) {
63  return promise_detail::Seq<Functors...>(std::move(functors)...);
64 }
65 
66 template <typename F>
67 F Seq(F functor) {
68  return functor;
69 }
70 
71 // Execute a sequence of operations of unknown length.
72 // Asynchronously:
73 // for (element in (begin, end)) {
74 // argument = wait_for factory(element, argument);
75 // }
76 // return argument;
77 template <typename Iter, typename Factory, typename Argument>
78 promise_detail::BasicSeqIter<promise_detail::SeqTraits, Factory, Argument, Iter>
79 SeqIter(Iter begin, Iter end, Argument argument, Factory factory) {
81  Argument, Iter>(
82  begin, end, std::move(factory), std::move(argument));
83 }
84 
85 } // namespace grpc_core
86 
87 #endif // GRPC_CORE_LIB_PROMISE_SEQ_H
grpc_core::promise_detail::BasicSeqIter
Definition: basic_seq.h:410
begin
char * begin
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1007
grpc_core::promise_detail::SeqTraits
Definition: seq.h:30
grpc_core
Definition: call_metric_recorder.h:31
elem
Timer elem
Definition: event_engine/iomgr_event_engine/timer_heap_test.cc:109
grpc_core::promise_detail::SeqTraits::CheckResultAndRunNext
static Poll< Result > CheckResultAndRunNext(PriorResult prior, RunNext run_next)
Definition: seq.h:44
absl::base_internal::Next
static AllocList * Next(int i, AllocList *prev, LowLevelAlloc::Arena *arena)
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:453
T
#define T(upbtypeconst, upbtype, ctype, default_value)
grpc_core::promise_detail::SeqTraits::WrappedType
T WrappedType
Definition: seq.h:32
gen_gtest_pred_impl.Iter
def Iter(n, format, sep='')
Definition: bloaty/third_party/googletest/googletest/scripts/gen_gtest_pred_impl.py:188
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
end
char * end
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1008
argument
Definition: third_party/boringssl-with-bazel/src/tool/internal.h:108
F
#define F(b, c, d)
Definition: md4.c:112
value
const char * value
Definition: hpack_parser_table.cc:165
poll.h
next
AllocList * next[kMaxLevel]
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:100
grpc_core::promise_detail::BasicSeq
Definition: basic_seq.h:199
grpc_core::promise_detail::SeqTraits::UnwrappedType
T UnwrappedType
Definition: seq.h:31
grpc_core::promise_detail::SeqTraits::CallFactory
static auto CallFactory(Next *next, T &&value) -> decltype(next->Once(std::forward< T >(value)))
Definition: seq.h:34
grpc_core::SeqIter
promise_detail::BasicSeqIter< promise_detail::SeqTraits, Factory, Argument, Iter > SeqIter(Iter begin, Iter end, Argument argument, Factory factory)
Definition: seq.h:79
grpc_core::Seq
promise_detail::Seq< Functors... > Seq(Functors... functors)
Definition: seq.h:62
absl::variant
Definition: abseil-cpp/absl/types/internal/variant.h:46
basic_seq.h
grpc_core::promise_detail::SeqTraits::CallSeqFactory
static auto CallSeqFactory(F &f, Elem &&elem, T &&value) -> decltype(f(std::forward< Elem >(elem), std::forward< T >(value)))
Definition: seq.h:39
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:16