userver: userver/ugrpc/impl/async_method_invocation.hpp Source File
Loading...
Searching...
No Matches
async_method_invocation.hpp
1#pragma once
2
3#include <userver/engine/single_consumer_event.hpp>
4
5USERVER_NAMESPACE_BEGIN
6
7namespace ugrpc::impl {
8
9class EventBase {
10 public:
11 /// @brief For use from the blocking call queue
12 /// @param `bool ok` returned by `grpc::CompletionQueue::Next`
13 virtual void Notify(bool ok) noexcept = 0;
14
15 protected:
16 // One should not call destructor by pointer to interface.
17 ~EventBase();
18};
19
20class AsyncMethodInvocation : public EventBase {
21 public:
22 virtual ~AsyncMethodInvocation();
23
24 /// @brief For use from coroutines
25 /// @return This object's `void* tag` for `grpc::CompletionQueue::Next`
26 void* GetTag() noexcept;
27
28 /// @see EventBase::Notify
29 void Notify(bool ok) noexcept override;
30
31 bool IsBusy() const noexcept;
32
33 enum class WaitStatus {
34 kOk,
35 kError,
36 kCancelled,
37 };
38
39 /// @brief For use from coroutines
40 /// @return `bool ok` returned by `grpc::CompletionQueue::Next`
41 [[nodiscard]] WaitStatus Wait() noexcept;
42
43 /// @brief Checks if the asynchronous call has completed
44 /// @return true if event returned from `grpc::CompletionQueue::Next`
45 [[nodiscard]] bool IsReady() const noexcept;
46
47 private:
48 bool ok_{false};
49 bool busy_{false};
50 engine::SingleConsumerEvent event_;
51};
52
53} // namespace ugrpc::impl
54
55USERVER_NAMESPACE_END