poll.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_POLL_H
16 #define GRPC_CORE_LIB_PROMISE_POLL_H
17 
19 
20 #include <stddef.h>
21 
22 #include "absl/types/variant.h"
23 
24 namespace grpc_core {
25 
26 // A type that signals a Promise is still pending and not yet completed.
27 // Allows writing 'return Pending{}' and with automatic conversions gets
28 // upgraded to a Poll<> object.
29 struct Pending {
30  constexpr bool operator==(Pending) const { return true; }
31 };
32 
33 // The result of polling a Promise once.
34 //
35 // Can be either pending - the Promise has not yet completed, or ready -
36 // indicating that the Promise has completed AND should not be polled again.
37 template <typename T>
39 
40 template <typename T, typename U>
42  if (absl::holds_alternative<Pending>(poll)) return Pending{};
43  return std::move(absl::get<U>(poll));
44 }
45 
46 // Variant of Poll that serves as a ready value
47 static constexpr size_t kPollReadyIdx = 1;
48 
49 // PollTraits tells us whether a type is Poll<> or some other type, and is
50 // leveraged in the PromiseLike/PromiseFactory machinery to select the
51 // appropriate implementation of those concepts based upon the return type of a
52 // lambda, for example (via enable_if).
53 template <typename T>
54 struct PollTraits {
55  static constexpr bool is_poll() { return false; }
56 };
57 
58 template <typename T>
59 struct PollTraits<Poll<T>> {
60  using Type = T;
61  static constexpr bool is_poll() { return true; }
62 };
63 
64 } // namespace grpc_core
65 
66 #endif // GRPC_CORE_LIB_PROMISE_POLL_H
grpc_core::PollTraits::is_poll
static constexpr bool is_poll()
Definition: poll.h:55
grpc_core::PollTraits< Poll< T > >::is_poll
static constexpr bool is_poll()
Definition: poll.h:61
grpc_core::poll_cast
Poll< T > poll_cast(Poll< U > poll)
Definition: poll.h:41
grpc_core
Definition: call_metric_recorder.h:31
grpc_core::PollTraits< Poll< T > >::Type
T Type
Definition: poll.h:60
T
#define T(upbtypeconst, upbtype, ctype, default_value)
grpc_core::Pending::operator==
constexpr bool operator==(Pending) const
Definition: poll.h:30
grpc_core::Pending
Definition: poll.h:29
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
grpc_core::PollTraits
Definition: poll.h:54
grpc_core::kPollReadyIdx
static constexpr size_t kPollReadyIdx
Definition: poll.h:47
absl::variant
Definition: abseil-cpp/absl/types/internal/variant.h:46
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:53