asio-grpc v1.6.0
Asynchronous gRPC with Asio/unified executors
agrpc::PollContext< Executor, Traits > Class Template Reference

(experimental) Helper class to run a GrpcContext in a different execution context More...

#include <agrpc/pollContext.hpp>

Public Member Functions

template<class Exec >
 PollContext (Exec &&executor)
 Construct a PollContext from an Executor.
 
void async_poll (agrpc::GrpcContext &grpc_context)
 Repeatedly call .poll() on the GrpcContext until it is stopped.
 
template<class StopPredicate >
void async_poll (agrpc::GrpcContext &grpc_context, StopPredicate stop_predicate)
 Repeatedly call .poll() on the GrpcContext until the provided StopPredicate returns true. More...
 

Detailed Description

template<class Executor, class Traits = agrpc::DefaultPollContextTraits>
class agrpc::PollContext< Executor, Traits >

(experimental) Helper class to run a GrpcContext in a different execution context

Example showing how to share a thread with an asio::io_context:

asio::io_context io_context;
agrpc::PollContext poll_context{io_context.get_executor()};
std::optional guard{asio::require(grpc_context.get_executor(), asio::execution::outstanding_work_t::tracked)};
poll_context.async_poll(grpc_context);
// Use io_context and grpc_context and reset the guard when done.
io_context.run();
(experimental) Helper class to run a GrpcContext in a different execution context
Definition: pollContext.hpp:79
void async_poll(agrpc::GrpcContext &grpc_context)
Repeatedly call .poll() on the GrpcContext until it is stopped.
Definition: pollContext.hpp:215
Template Parameters
ExecutorThe executor type
TraitsThe traits type, defaults to agrpc::DefaultPollContextTraits. If the static assertion 'OneShotAllocator has insufficient capacity' fails then create your own traits to increase the buffer size of the PollContext. Example:
struct MyTraits
{
static constexpr std::size_t BUFFER_SIZE{256};
}
Before asio-grpc 1.6.0 the custom traits had to inherit from the default: struct MyTraits : agrpc::DefaultPollContextTraits.
Since
1.5.0

Member Function Documentation

◆ async_poll()

template<class Executor , class Traits >
template<class StopPredicate >
void agrpc::PollContext< Executor, Traits >::async_poll ( agrpc::GrpcContext grpc_context,
StopPredicate  stop_predicate 
)

Repeatedly call .poll() on the GrpcContext until the provided StopPredicate returns true.

Parameters
stop_predicateA function that returns true when the polling should stop. Its signature should be bool(agrpc::GrpcContext&).