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

Function object to wait for timers. More...

#include <agrpc/wait.hpp>

Public Member Functions

template<class Deadline , class CompletionToken = agrpc::DefaultCompletionToken>
auto operator() (grpc::Alarm &alarm, const Deadline &deadline, CompletionToken &&token={}) const noexcept(detail::IS_NOTRHOW_GRPC_INITIATE_COMPLETION_TOKEN< CompletionToken > &&std::is_nothrow_copy_constructible_v< Deadline >)
 Wait for a grpc::Alarm More...
 

Detailed Description

Function object to wait for timers.

Attention
The completion handler created from the completion token that is provided to the functions described below must have an associated executor that refers to a GrpcContext:
asio::io_context io_context;
asio::co_spawn(
io_context,
[&]() -> asio::awaitable<void>
{
grpc::ServerContext server_context;
grpc::ServerAsyncReader<example::v1::Response, example::v1::Request> reader{&server_context};
// error: asio::this_coro::executor does not refer to a GrpcContext
// co_await agrpc::request(&example::v1::Example::AsyncService::RequestClientStreaming, service,
// server_context, reader, asio::use_awaitable);
// correct:
co_await agrpc::request(&example::v1::Example::AsyncService::RequestClientStreaming, service,
server_context, reader, asio::bind_executor(grpc_context, asio::use_awaitable));
},
asio::detached);
constexpr detail::RequestFn request
Start a new RPC.
Definition: rpc.hpp:1394

Member Function Documentation

◆ operator()()

template<class Deadline , class CompletionToken = agrpc::DefaultCompletionToken>
auto agrpc::detail::WaitFn::operator() ( grpc::Alarm &  alarm,
const Deadline &  deadline,
CompletionToken &&  token = {} 
) const
inlinenoexcept

Wait for a grpc::Alarm

The operation finishes once the alarm expires (at deadline) or is cancelled (see Cancel). If the alarm expired, the result will be true, false otherwise (ie, upon cancellation).

Example:

grpc::Alarm alarm;
bool wait_ok =
co_await agrpc::wait(alarm, std::chrono::system_clock::now() + std::chrono::seconds(1), asio::use_awaitable);
constexpr detail::WaitFn wait
Wait for a timer.
Definition: wait.hpp:72
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 the one created by agrpc::use_sender. The completion signature is void(bool). true if it expired, false if it was canceled.