asio-grpc v3.1.0
Asynchronous gRPC with Asio/unified executors
agrpc::detail::NotifyOnStateChangeFn Struct Reference

Function to set notification for a grpc::Channel state change. More...

#include <agrpc/notify_on_state_change.hpp>

Public Member Functions

template<class Deadline , class CompletionToken >
auto operator() (agrpc::GrpcContext &grpc_context, grpc::ChannelInterface &channel, ::grpc_connectivity_state last_observed, Deadline deadline, CompletionToken &&token) const noexcept(detail::IS_USE_SENDER< CompletionToken > &&std::is_nothrow_copy_constructible_v< Deadline >)
 Set notification for a grpc::Channel state change. More...
 

Detailed Description

Function to set notification for a grpc::Channel state change.

Wait for the channel state to change or the specified deadline to expire.

Per-Operation Cancellation

None.

Since
2.3.0

Member Function Documentation

◆ operator()()

template<class Deadline , class CompletionToken >
auto agrpc::detail::NotifyOnStateChangeFn::operator() ( agrpc::GrpcContext grpc_context,
grpc::ChannelInterface &  channel,
::grpc_connectivity_state  last_observed,
Deadline  deadline,
CompletionToken &&  token 
) const
inlinenoexcept

Set notification for a grpc::Channel state change.

Wait for the channel state to change or the specified deadline to expire.

Example:

const auto channel = grpc::CreateChannel(host, grpc::InsecureChannelCredentials());
const auto state = channel->GetState(true);
const auto deadline = std::chrono::system_clock::now() + std::chrono::seconds(5);
bool has_state_changed =
co_await agrpc::notify_on_state_change(grpc_context, *channel, state, deadline, asio::use_awaitable);
constexpr detail::NotifyOnStateChangeFn notify_on_state_change
Set notification for a grpc::Channel state change.
Definition: notify_on_state_change.hpp:80
Parameters
deadlineBy default gRPC supports two types of deadlines: gpr_timespec and std::chrono::system_clock::time_point. More types can be added by specializing grpc::TimePoint.
tokenA completion token like asio::yield_context or agrpc::use_sender. The completion signature is void(bool). true if the state changed, false if the deadline expired.