asio-grpc v1.5.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>
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()};
auto guard = asio::make_work_guard(grpc_context);
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:86
Template Parameters
ExecutorThe executor type
TraitsThe traits type, defaults to agrpc::DefaultPollContextTraits. If the static assertion 'OneShotAllocator has insufficient capacity' triggers then inherit from the default to increase the buffer size of the PollContext. Example:
{
static constexpr std::size_t BUFFER_SIZE = 128;
}
(experimental) Default PollContext traits
Definition: pollContext.hpp:32
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 
)
inline

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&).