aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorGravatar Vijay Pai <vpai@google.com>2017-08-21 22:34:37 -0700
committerGravatar Vijay Pai <vpai@google.com>2017-09-14 17:55:13 -0700
commit4b047a3bff92ff377205be38d9044b9d99e06fbb (patch)
tree73af614582d8b6daf2e277a8f32b5bd122100d81 /examples
parentc3aba91be94d336a27f945a644233bc244f22e2b (diff)
Construction of streams shouldn't require triggering async ops
Diffstat (limited to 'examples')
-rw-r--r--examples/cpp/helloworld/greeter_async_client.cc12
-rw-r--r--examples/cpp/helloworld/greeter_async_client2.cc14
2 files changed, 17 insertions, 9 deletions
diff --git a/examples/cpp/helloworld/greeter_async_client.cc b/examples/cpp/helloworld/greeter_async_client.cc
index 64da044ea6..ddf6c1aaf3 100644
--- a/examples/cpp/helloworld/greeter_async_client.cc
+++ b/examples/cpp/helloworld/greeter_async_client.cc
@@ -60,11 +60,15 @@ class GreeterClient {
// Storage for the status of the RPC upon completion.
Status status;
- // stub_->AsyncSayHello() performs the RPC call, returning an instance we
- // store in "rpc". Because we are using the asynchronous API, we need to
- // hold on to the "rpc" instance in order to get updates on the ongoing RPC.
+ // stub_->PrepareAsyncSayHello() creates an RPC object, returning
+ // an instance to store in "call" but does not actually start the RPC
+ // Because we are using the asynchronous API, we need to hold on to
+ // the "call" instance in order to get updates on the ongoing RPC.
std::unique_ptr<ClientAsyncResponseReader<HelloReply> > rpc(
- stub_->AsyncSayHello(&context, request, &cq));
+ stub_->PrepareAsyncSayHello(&context, request, &cq));
+
+ // StartCall initiates the RPC call
+ rpc->StartCall();
// Request that, upon completion of the RPC, "reply" be updated with the
// server's response; "status" with the indication of whether the operation
diff --git a/examples/cpp/helloworld/greeter_async_client2.cc b/examples/cpp/helloworld/greeter_async_client2.cc
index 4192546bef..3154e84d85 100644
--- a/examples/cpp/helloworld/greeter_async_client2.cc
+++ b/examples/cpp/helloworld/greeter_async_client2.cc
@@ -49,11 +49,15 @@ class GreeterClient {
// Call object to store rpc data
AsyncClientCall* call = new AsyncClientCall;
- // stub_->AsyncSayHello() performs the RPC call, returning an instance to
- // store in "call". Because we are using the asynchronous API, we need to
- // hold on to the "call" instance in order to get updates on the ongoing RPC.
- call->response_reader = stub_->AsyncSayHello(&call->context, request, &cq_);
-
+ // stub_->PrepareAsyncSayHello() creates an RPC object, returning
+ // an instance to store in "call" but does not actually start the RPC
+ // Because we are using the asynchronous API, we need to hold on to
+ // the "call" instance in order to get updates on the ongoing RPC.
+ call->response_reader =
+ stub_->PrepareAsyncSayHello(&call->context, request, &cq_);
+
+ // StartCall initiates the RPC call
+ call->response_reader->StartCall();
// Request that, upon completion of the RPC, "reply" be updated with the
// server's response; "status" with the indication of whether the operation