asio-grpc v1.6.0
Asynchronous gRPC with Asio/unified executors
agrpc::detail::GrpcInitiateFn Struct Reference

Function object to initiate gRPC tag-based functions. More...

#include <agrpc/grpcInitiate.hpp>

Public Member Functions

template<class InitiatingFunction , class CompletionToken = agrpc::DefaultCompletionToken>
auto operator() (InitiatingFunction initiating_function, CompletionToken &&token={}) const
 Initiate a gRPC tag-based function. More...
 

Detailed Description

Function object to initiate gRPC tag-based functions.

Member Function Documentation

◆ operator()()

template<class InitiatingFunction , class CompletionToken = agrpc::DefaultCompletionToken>
auto agrpc::detail::GrpcInitiateFn::operator() ( InitiatingFunction  initiating_function,
CompletionToken &&  token = {} 
) const
inline

Initiate a gRPC tag-based function.

This function can be used to lift tag-based gRPC functions that are not covered by agrpc/rpc.hpp into the Asio/unifex world.

Example showing how to asynchronously wait for a gRPC channel to change its state:

auto channel = grpc::CreateChannel(host, grpc::InsecureChannelCredentials());
auto state = channel->GetState(true);
auto deadline = std::chrono::system_clock::now() + std::chrono::seconds(5);
bool is_deadline_not_expired = co_await agrpc::grpc_initiate(
[&](agrpc::GrpcContext& grpc_context, void* tag)
{
channel->NotifyOnStateChange(state, deadline, agrpc::get_completion_queue(grpc_context), tag);
},
asio::use_awaitable);
Execution context based on grpc::CompletionQueue
Definition: grpcContext.hpp:50
constexpr detail::GetCompletionQueueFn get_completion_queue
Get grpc::CompletionQueue* from an object.
Definition: getCompletionQueue.hpp:107
constexpr detail::GrpcInitiateFn grpc_initiate
Initiate a gRPC tag-based function.
Definition: grpcInitiate.hpp:61
Parameters
initiating_functionSignature must be void(agrpc::GrpcContext&, void*).
tokenA completion token like asio::yield_context or the one created by agrpc::use_sender. The completion signature is void(bool).