Google Cloud C++ Client  1.32.1
C++ Client Library for Google Cloud Platform
Public Member Functions | List of all members
google::cloud::v1::CompletionQueue Class Reference

Call the functor associated with asynchronous operations when they complete. More...

#include <google/cloud/completion_queue.h>

Public Member Functions

 CompletionQueue ()
 
 CompletionQueue (std::shared_ptr< internal::CompletionQueueImpl > impl)
 
void Run ()
 Run the completion queue event loop. More...
 
void Shutdown ()
 Terminate the completion queue event loop. More...
 
void CancelAll ()
 Cancel all pending operations. More...
 
google::cloud::future< StatusOr< std::chrono::system_clock::time_point > > MakeDeadlineTimer (std::chrono::system_clock::time_point deadline)
 Create a timer that fires at deadline. More...
 
template<typename Rep , typename Period >
future< StatusOr< std::chrono::system_clock::time_point > > MakeRelativeTimer (std::chrono::duration< Rep, Period > duration)
 Create a timer that fires after the duration. More...
 
template<typename AsyncCallType , typename Request , typename Sig = internal::AsyncCallResponseType<AsyncCallType, Request>, typename Response = typename Sig::type, typename std::enable_if< Sig::value, int >::type = 0>
future< StatusOr< Response > > MakeUnaryRpc (AsyncCallType async_call, Request const &request, std::unique_ptr< grpc::ClientContext > context)
 Make an asynchronous unary RPC. More...
 
template<typename AsyncCallType , typename Request , typename Response = typename internal:: AsyncStreamingReadResponseType<AsyncCallType, Request>::type, typename OnReadHandler , typename OnFinishHandler >
std::shared_ptr< AsyncOperationMakeStreamingReadRpc (AsyncCallType &&async_call, Request const &request, std::unique_ptr< grpc::ClientContext > context, OnReadHandler &&on_read, OnFinishHandler &&on_finish)
 Make an asynchronous streaming read RPC. More...
 
template<typename Functor , typename std::enable_if< internal::CheckRunAsyncCallback< Functor >::value, int >::type = 0>
void RunAsync (Functor &&functor)
 Asynchronously run a functor on a thread Run()ning the CompletionQueue. More...
 
template<typename Functor , typename std::enable_if< internal::is_invocable< Functor >::value, int >::type = 0>
void RunAsync (Functor &&functor)
 Asynchronously run a functor on a thread Run()ning the CompletionQueue. More...
 
future< StatusAsyncWaitConnectionReady (std::shared_ptr< grpc::Channel > channel, std::chrono::system_clock::time_point deadline)
 Asynchronously wait for a connection to become ready. More...
 

Detailed Description

Call the functor associated with asynchronous operations when they complete.

Definition at line 41 of file completion_queue.h.

Constructor & Destructor Documentation

◆ CompletionQueue() [1/2]

google::cloud::v1::CompletionQueue::CompletionQueue ( )

Definition at line 23 of file completion_queue.cc.

◆ CompletionQueue() [2/2]

google::cloud::v1::CompletionQueue::CompletionQueue ( std::shared_ptr< internal::CompletionQueueImpl >  impl)
inlineexplicit

Definition at line 44 of file completion_queue.h.

Member Function Documentation

◆ AsyncWaitConnectionReady()

future< Status > google::cloud::v1::CompletionQueue::AsyncWaitConnectionReady ( std::shared_ptr< grpc::Channel >  channel,
std::chrono::system_clock::time_point  deadline 
)

Asynchronously wait for a connection to become ready.

Parameters
channelthe channel on which to wait for state changes
deadlinegive up waiting for the state change if this deadline passes
Returns
future<> which will be satisfied when either of these events happen: (a) the connection is ready, (b) the connection permanently failed, (c) deadline passes before (a) or (b) happen; the future will be satisfied with StatusCode::kOk for (a), StatusCode::kCancelled for (b) and StatusCode::kDeadlineExceeded for (c)

Definition at line 26 of file completion_queue.cc.

◆ CancelAll()

void google::cloud::v1::CompletionQueue::CancelAll ( )
inline

Cancel all pending operations.

Definition at line 59 of file completion_queue.h.

◆ MakeDeadlineTimer()

google::cloud::future<StatusOr<std::chrono::system_clock::time_point> > google::cloud::v1::CompletionQueue::MakeDeadlineTimer ( std::chrono::system_clock::time_point  deadline)
inline

Create a timer that fires at deadline.

Parameters
deadlinewhen should the timer expire.
Returns
a future that becomes satisfied after deadline. The result of the future is the time at which it expired, or an error Status if the timer did not run to expiration (e.g. it was cancelled).

Definition at line 71 of file completion_queue.h.

◆ MakeRelativeTimer()

template<typename Rep , typename Period >
future<StatusOr<std::chrono::system_clock::time_point> > google::cloud::v1::CompletionQueue::MakeRelativeTimer ( std::chrono::duration< Rep, Period >  duration)
inline

Create a timer that fires after the duration.

Template Parameters
Repa placeholder to match the Rep tparam for duration type, the semantics of this template parameter are documented in std::chrono::duration<> (in brief, the underlying arithmetic type used to store the number of ticks), for our purposes it is simply a formal parameter.
Perioda placeholder to match the Period tparam for duration type, the semantics of this template parameter are documented in std::chrono::duration<> (in brief, the length of the tick in seconds, expressed as a std::ratio<>), for our purposes it is simply a formal parameter.
Parameters
durationwhen should the timer expire relative to the current time.
Returns
a future that becomes satisfied after duration time has elapsed. The result of the future is the time at which it expired, or an error Status if the timer did not run to expiration (e.g. it was cancelled).

Definition at line 96 of file completion_queue.h.

◆ MakeStreamingReadRpc()

template<typename AsyncCallType , typename Request , typename Response = typename internal:: AsyncStreamingReadResponseType<AsyncCallType, Request>::type, typename OnReadHandler , typename OnFinishHandler >
std::shared_ptr<AsyncOperation> google::cloud::v1::CompletionQueue::MakeStreamingReadRpc ( AsyncCallType &&  async_call,
Request const &  request,
std::unique_ptr< grpc::ClientContext >  context,
OnReadHandler &&  on_read,
OnFinishHandler &&  on_finish 
)
inline

Make an asynchronous streaming read RPC.

Reading from the stream starts automatically, and the handler is notified of all interesting events in the stream. Note that then handler is called by any thread blocked on this object's Run() member function. However, only one callback in the handler is called at a time.

Parameters
async_calla callable to start the asynchronous RPC.
requestthe contents of the request.
contextan initialized request context to make the call.
on_readthe callback to be invoked on each successful Read().
on_finishthe callback to be invoked when the stream is closed.
Template Parameters
AsyncCallTypethe type of async_call. It must be invocable with parameters (grpc::ClientContext*, RequestType const&, grpc::CompletionQueue*). Furthermore, it should return a type convertible to std::unique_ptr<grpc::ClientAsyncReaderInterface<Response>>>. These requirements are verified by internal::AsyncStreamingReadRpcUnwrap<>, and this function is excluded from overload resolution if the parameters do not meet these requirements.
Requestthe type of the request in the streaming RPC.
Responsethe type of the response in the streaming RPC.
OnReadHandlerthe type of the on_read callback.
OnFinishHandlerthe type of the on_finish callback.

Definition at line 169 of file completion_queue.h.

◆ MakeUnaryRpc()

template<typename AsyncCallType , typename Request , typename Sig = internal::AsyncCallResponseType<AsyncCallType, Request>, typename Response = typename Sig::type, typename std::enable_if< Sig::value, int >::type = 0>
future<StatusOr<Response> > google::cloud::v1::CompletionQueue::MakeUnaryRpc ( AsyncCallType  async_call,
Request const &  request,
std::unique_ptr< grpc::ClientContext >  context 
)
inline

Make an asynchronous unary RPC.

Parameters
async_calla callable to start the asynchronous RPC.
requestthe contents of the request.
contextan initialized request context to make the call.
Template Parameters
AsyncCallTypethe type of async_call. It must be invocable with (grpc::ClientContext*, RequestType const&, grpc::CompletionQueue*). Furthermore, it should return a std::unique_ptr<grpc::ClientAsyncResponseReaderInterface<Response>>>. These requirements are verified by internal::CheckAsyncUnaryRpcSignature<>, and this function is excluded from overload resolution if the parameters do not meet these requirements.
Requestthe type of the request parameter in the gRPC.
Returns
a future that becomes satisfied when the operation completes.

Definition at line 126 of file completion_queue.h.

◆ Run()

void google::cloud::v1::CompletionQueue::Run ( )
inline

Run the completion queue event loop.

Note that more than one thread can call this member function, to create a pool of threads completing asynchronous operations.

Definition at line 53 of file completion_queue.h.

◆ RunAsync() [1/2]

template<typename Functor , typename std::enable_if< internal::CheckRunAsyncCallback< Functor >::value, int >::type = 0>
void google::cloud::v1::CompletionQueue::RunAsync ( Functor &&  functor)
inline

Asynchronously run a functor on a thread Run()ning the CompletionQueue.

Template Parameters
Functorthe functor to call on the CompletionQueue thread. It must satisfy the void(CompletionQueue&) signature.
Parameters
functorthe value of the functor.

Definition at line 191 of file completion_queue.h.

◆ RunAsync() [2/2]

template<typename Functor , typename std::enable_if< internal::is_invocable< Functor >::value, int >::type = 0>
void google::cloud::v1::CompletionQueue::RunAsync ( Functor &&  functor)
inline

Asynchronously run a functor on a thread Run()ning the CompletionQueue.

Template Parameters
Functorthe functor to call on the CompletionQueue thread. It must satisfy the void() signature.
Parameters
functorthe value of the functor.

Definition at line 222 of file completion_queue.h.

◆ Shutdown()

void google::cloud::v1::CompletionQueue::Shutdown ( )
inline

Terminate the completion queue event loop.

Definition at line 56 of file completion_queue.h.