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).
MakeRelativeTimer(std::chrono::duration< Rep, Period >)
Create a timer that fires after the duration.
Parameters
Name
Description
duration
std::chrono::duration< Rep, Period >
when should the timer expire relative to the current time.
typename Rep
a 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.
typename Period
a 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.
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).
the type of async_call. It must be invocable with (grpc::ClientContext*, Request 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.
typename Request
the type of the request parameter in the gRPC.
typename Response
the response from the asynchronous RPC.
Returns
Type
Description
future< StatusOr< Response > >
a future that becomes satisfied when the operation completes.
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
Name
Description
async_call
AsyncCallType &&
a callable to start the asynchronous RPC.
request
Request const &
the contents of the request.
context
std::unique_ptr< grpc::ClientContext >
an initialized request context to make the call.
on_read
OnReadHandler &&
the callback to be invoked on each successful Read().
on_finish
OnFinishHandler &&
the callback to be invoked when the stream is closed.
typename AsyncCallType
the 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.
Asynchronously wait for a connection to become ready.
Parameters
Name
Description
channel
std::shared_ptr< grpc::Channel >
the channel on which to wait for state changes
deadline
std::chrono::system_clock::time_point
give up waiting for the state change if this deadline passes
Returns
Type
Description
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 with StatusCode::kOk for (a), StatusCode::kCancelled for (b) and StatusCode::kDeadlineExceeded for (c)
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-14 UTC."],[[["\u003cp\u003eThe latest version of the \u003ccode\u003eCompletionQueue\u003c/code\u003e documentation is 2.37.0-rc, and the page contains documentation for multiple other versions, including 2.36.0, 2.35.0, all the way down to 2.10.1.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eCompletionQueue\u003c/code\u003e manages an event loop that processes asynchronous operations by calling the associated functor upon completion.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eRun()\u003c/code\u003e function executes the event loop and can be called by multiple threads, effectively creating a pool of threads to handle asynchronous operations.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eCompletionQueue\u003c/code\u003e object has capabilities to create and manage timers, handling both absolute deadlines via \u003ccode\u003eMakeDeadlineTimer\u003c/code\u003e and relative durations with \u003ccode\u003eMakeRelativeTimer\u003c/code\u003e, which can be cancelled as well.\u003c/p\u003e\n"],["\u003cp\u003eIt offers functions to manage RPC operations, like \u003ccode\u003eMakeUnaryRpc\u003c/code\u003e for unary requests and \u003ccode\u003eMakeStreamingReadRpc\u003c/code\u003e for streaming read operations, as well as other asynchronous operation management through \u003ccode\u003eRunAsync\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["# Class CompletionQueue (2.22.1)\n\nVersion 2.22.1keyboard_arrow_down\n\n- [2.42.0-rc (latest)](/cpp/docs/reference/common/latest/classgoogle_1_1cloud_1_1CompletionQueue)\n- [2.41.0](/cpp/docs/reference/common/2.41.0/classgoogle_1_1cloud_1_1CompletionQueue)\n- [2.40.0](/cpp/docs/reference/common/2.40.0/classgoogle_1_1cloud_1_1CompletionQueue)\n- [2.39.0](/cpp/docs/reference/common/2.39.0/classgoogle_1_1cloud_1_1CompletionQueue)\n- [2.38.0](/cpp/docs/reference/common/2.38.0/classgoogle_1_1cloud_1_1CompletionQueue)\n- [2.37.0](/cpp/docs/reference/common/2.37.0/classgoogle_1_1cloud_1_1CompletionQueue)\n- [2.36.0](/cpp/docs/reference/common/2.36.0/classgoogle_1_1cloud_1_1CompletionQueue)\n- [2.35.0](/cpp/docs/reference/common/2.35.0/classgoogle_1_1cloud_1_1CompletionQueue)\n- [2.34.0](/cpp/docs/reference/common/2.34.0/classgoogle_1_1cloud_1_1CompletionQueue)\n- [2.33.0](/cpp/docs/reference/common/2.33.0/classgoogle_1_1cloud_1_1CompletionQueue)\n- [2.32.0](/cpp/docs/reference/common/2.32.0/classgoogle_1_1cloud_1_1CompletionQueue)\n- [2.31.0](/cpp/docs/reference/common/2.31.0/classgoogle_1_1cloud_1_1CompletionQueue)\n- [2.30.0](/cpp/docs/reference/common/2.30.0/classgoogle_1_1cloud_1_1CompletionQueue)\n- [2.29.0](/cpp/docs/reference/common/2.29.0/classgoogle_1_1cloud_1_1CompletionQueue)\n- [2.28.0](/cpp/docs/reference/common/2.28.0/classgoogle_1_1cloud_1_1CompletionQueue)\n- [2.27.0](/cpp/docs/reference/common/2.27.0/classgoogle_1_1cloud_1_1CompletionQueue)\n- [2.26.0](/cpp/docs/reference/common/2.26.0/classgoogle_1_1cloud_1_1CompletionQueue)\n- [2.25.1](/cpp/docs/reference/common/2.25.1/classgoogle_1_1cloud_1_1CompletionQueue)\n- [2.24.0](/cpp/docs/reference/common/2.24.0/classgoogle_1_1cloud_1_1CompletionQueue)\n- [2.23.0](/cpp/docs/reference/common/2.23.0/classgoogle_1_1cloud_1_1CompletionQueue)\n- [2.22.1](/cpp/docs/reference/common/2.22.1/classgoogle_1_1cloud_1_1CompletionQueue)\n- [2.21.0](/cpp/docs/reference/common/2.21.0/classgoogle_1_1cloud_1_1CompletionQueue)\n- [2.20.0](/cpp/docs/reference/common/2.20.0/classgoogle_1_1cloud_1_1CompletionQueue)\n- [2.19.0](/cpp/docs/reference/common/2.19.0/classgoogle_1_1cloud_1_1CompletionQueue)\n- [2.18.0](/cpp/docs/reference/common/2.18.0/classgoogle_1_1cloud_1_1CompletionQueue)\n- [2.17.0](/cpp/docs/reference/common/2.17.0/classgoogle_1_1cloud_1_1CompletionQueue)\n- [2.16.0](/cpp/docs/reference/common/2.16.0/classgoogle_1_1cloud_1_1CompletionQueue)\n- [2.15.1](/cpp/docs/reference/common/2.15.1/classgoogle_1_1cloud_1_1CompletionQueue)\n- [2.14.0](/cpp/docs/reference/common/2.14.0/classgoogle_1_1cloud_1_1CompletionQueue)\n- [2.13.0](/cpp/docs/reference/common/2.13.0/classgoogle_1_1cloud_1_1CompletionQueue)\n- [2.12.0](/cpp/docs/reference/common/2.12.0/classgoogle_1_1cloud_1_1CompletionQueue)\n- [2.11.0](/cpp/docs/reference/common/2.11.0/classgoogle_1_1cloud_1_1CompletionQueue)\n- [2.10.1](/cpp/docs/reference/common/2.10.1/classgoogle_1_1cloud_1_1CompletionQueue) \nCall the functor associated with asynchronous operations when they complete.\n\nConstructors\n------------\n\n### CompletionQueue()\n\n### CompletionQueue(std::shared_ptr\\\u003c internal::CompletionQueueImpl \\\u003e)\n\nFunctions\n---------\n\n### Run()\n\nRun the completion queue event loop. \nNote that more than one thread can call this member function, to create a pool of threads completing asynchronous operations.\n\n### Shutdown()\n\nTerminate the completion queue event loop.\n\n### CancelAll()\n\nCancel all pending operations.\n\n### MakeDeadlineTimer(std::chrono::system_clock::time_point)\n\nCreate a timer that fires at `deadline`.\n\n### MakeRelativeTimer(std::chrono::duration\\\u003c Rep, Period \\\u003e)\n\nCreate a timer that fires after the `duration`.\n\n### MakeUnaryRpc(AsyncCallType, Request const \\&, std::unique_ptr\\\u003c grpc::ClientContext \\\u003e)\n\nMake an asynchronous unary RPC. \n| **Deprecated:** Applications should have no need to call this function. The libraries provide `Async*()` member functions in the generated (or) hand-crafted `*Client` classes for the same purpose.\n\n### MakeStreamingReadRpc(AsyncCallType \\&\\&, Request const \\&, std::unique_ptr\\\u003c grpc::ClientContext \\\u003e, OnReadHandler \\&\\&, OnFinishHandler \\&\\&)\n\nMake an asynchronous streaming read RPC. \nReading 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()](/cpp/docs/reference/common/2.22.1/classgoogle_1_1cloud_1_1CompletionQueue#classgoogle_1_1cloud_1_1CompletionQueue_1a9803235c77d3838d14b81f5200b204c4) member function. However, only one callback in the handler is called at a time.\n| **Deprecated:** Applications should have no need to call this function. The libraries provide `Async*()` member functions in the generated (or) hand-crafted `*Client` classes for the same purpose.\n\n### RunAsync(Functor \\&\\&)\n\nAsynchronously run a functor on a thread [`Run()`](/cpp/docs/reference/common/2.22.1/classgoogle_1_1cloud_1_1CompletionQueue#classgoogle_1_1cloud_1_1CompletionQueue_1a9803235c77d3838d14b81f5200b204c4)ning the [`CompletionQueue`](/cpp/docs/reference/common/2.22.1/classgoogle_1_1cloud_1_1CompletionQueue).\n\n### RunAsync(Functor \\&\\&)\n\nAsynchronously run a functor on a thread [`Run()`](/cpp/docs/reference/common/2.22.1/classgoogle_1_1cloud_1_1CompletionQueue#classgoogle_1_1cloud_1_1CompletionQueue_1a9803235c77d3838d14b81f5200b204c4)ning the [`CompletionQueue`](/cpp/docs/reference/common/2.22.1/classgoogle_1_1cloud_1_1CompletionQueue).\n\n### AsyncWaitConnectionReady(std::shared_ptr\\\u003c grpc::Channel \\\u003e, std::chrono::system_clock::time_point)\n\nAsynchronously wait for a connection to become ready."]]