Class CompletionQueue (2.46.0-rc)

Call the functor associated with asynchronous operations when they complete.

Constructors

CompletionQueue()

CompletionQueue(std::shared_ptr< internal::CompletionQueueImpl >)

Parameter
NameDescription
implstd::shared_ptr< internal::CompletionQueueImpl >

Functions

Run()

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.

Returns
TypeDescription
void

Shutdown()

Terminate the completion queue event loop.

Returns
TypeDescription
void

CancelAll()

Cancel all pending operations.

Returns
TypeDescription
void

MakeDeadlineTimer(std::chrono::system_clock::time_point)

Create a timer that fires atdeadline.

Parameter
NameDescription
deadlinestd::chrono::system_clock::time_point

when should the timer expire.

Returns
TypeDescription
google::cloud::future< StatusOr< std::chrono::system_clock::time_point > >

a future that becomes satisfied afterdeadline. The result of the future is the time at which it expired, or an errorStatus if the timer did not run to expiration (e.g. it was cancelled).

MakeRelativeTimer(std::chrono::duration< Rep, Period >)

Create a timer that fires after theduration.

Parameters
NameDescription
durationstd::chrono::duration< Rep, Period >

when should the timer expire relative to the current time.

typename Rep

a placeholder to match the Rep tparam forduration type, the semantics of this template parameter are documented instd::chrono::duration<> (in brief, the underlying arithmetic type used to store the number of ticks), for our purposes it is simply a formal parameter.

typename Period

a placeholder to match the Period tparam forduration type, the semantics of this template parameter are documented instd::chrono::duration<> (in brief, the length of the tick in seconds, expressed as astd::ratio<>), for our purposes it is simply a formal parameter.

Returns
TypeDescription
future< StatusOr< std::chrono::system_clock::time_point > >

a future that becomes satisfied afterduration time has elapsed. The result of the future is the time at which it expired, or an errorStatus if the timer did not run to expiration (e.g. it was cancelled).

MakeUnaryRpc(AsyncCallType, Request const &, std::unique_ptr< grpc::ClientContext >)

Make an asynchronous unary RPC.

Parameters
NameDescription
async_callAsyncCallType

a callable to start the asynchronous RPC.

requestRequest const &

the contents of the request.

contextstd::unique_ptr< grpc::ClientContext >

an initialized request context to make the call.

typename AsyncCallType

the type ofasync_call. It must be invocable with(grpc::ClientContext*, Request const&, grpc::CompletionQueue*). Furthermore, it should return astd::unique_ptr<grpc::ClientAsyncResponseReaderInterface<Response>>>. These requirements are verified byinternal::CheckAsyncUnaryRpcSignature<>, and this function is excluded from overload resolution if the parameters do not meet these requirements.

typename Request

the type of the request parameter in the gRPC.

typename Response

the response from the asynchronous RPC.

Returns
TypeDescription
future< StatusOr< Response > >

a future that becomes satisfied when the operation completes.

MakeStreamingReadRpc(AsyncCallType &&, Request const &, std::unique_ptr< grpc::ClientContext >, OnReadHandler &&, OnFinishHandler &&)

Parameters
NameDescription
async_callAsyncCallType &&

a callable to start the asynchronous RPC.

requestRequest const &

the contents of the request.

contextstd::unique_ptr< grpc::ClientContext >

an initialized request context to make the call.

on_readOnReadHandler &&

the callback to be invoked on each successful Read().

on_finishOnFinishHandler &&

the callback to be invoked when the stream is closed.

typename AsyncCallType

the type ofasync_call. It must be invocable with parameters(grpc::ClientContext*, RequestType const&, grpc::CompletionQueue*). Furthermore, it should return a type convertible tostd::unique_ptr<grpc::ClientAsyncReaderInterface<Response>>>. These requirements are verified byinternal::AsyncStreamingReadRpcUnwrap<>, and this function is excluded from overload resolution if the parameters do not meet these requirements.

typename Request

the type of the request in the streaming RPC.

typename Response

the type of the response in the streaming RPC.

typename OnReadHandler

the type of theon_read callback.

typename OnFinishHandler

the type of theon_finish callback.

Returns
TypeDescription
std::shared_ptr< AsyncOperation >

RunAsync(Functor &&)

Parameters
NameDescription
functorFunctor &&

the functor to call in one of theCompletionQueue's threads.

typename Functor

the type offunctor. It must satisfystd::is_invocable<Functor>.

Returns
TypeDescription
void

RunAsync(Functor &&)

Asynchronously run a functor on a threadRun()ning theCompletionQueue.

Parameters
NameDescription
functorFunctor &&

the functor to call in one of theCompletionQueue's threads.

typename Functor

the type offunctor. It must satisfystd::is_invocable<Functor>.

Returns
TypeDescription
void

AsyncWaitConnectionReady(std::shared_ptr< grpc::Channel >, std::chrono::system_clock::time_point)

Asynchronously wait for a connection to become ready.

Parameters
NameDescription
channelstd::shared_ptr< grpc::Channel >

the channel on which to wait for state changes

deadlinestd::chrono::system_clock::time_point

give up waiting for the state change if this deadline passes

Returns
TypeDescription
future< Status >

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 withStatusCode::kOk for (a),StatusCode::kCancelled for (b) andStatusCode::kDeadlineExceeded for (c)

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-17 UTC.