I am trying to use the async bidi reactor callback APIs by following the 
documentation in the proposal 
(https://github.com/grpc/proposal/blob/master/L67-cpp-callback-api.md. I 
could not find another source of documentation). The current documentation 
is not clarifying a few things.

1) If I am implementing a bidi streaming client 
using ClientBidiReactor<T1,T2> , Would the *StartRead(Response* resp)* 
waits for a new message to arrive at the stream (from server)? My testing 
so far shows that the *OnReadDone *is called right away with Boolean value 
false. It is not waiting for the message to arrive. In that case, am I 
supposed to keep calling the StartRead in a never exiting loop to get the 
message when it is available to consume from the stream?

2) When the *OnReadDone *is called with true value, What If I want to pass 
the Response object to another method for processing (which may be a long 
running operation), but still want to do a StartRead operation at the same 
time. The current API forces us to use a global variable between the 2 
calls (StartRead and OnReadDone) to get the data which may cause data 
corruption(A new response object is placed when the previous message is 
still being processed. see code sample below). What is the recommended 
approach to handle this scenario? I want to offload the processing to an 
async call like

void OnReadDone(bool ok) {
  if (ok) {
    auto f = std::async(launch::async, [this]() {
        handler_->Process(messageFromServer_);  // this may take a long 
time.
    });           

    StartRead(&messageFromServer_);
  }       
}
Appreciate some guidance here. Thank you!

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/7356c268-1ccf-49a5-8f78-9d4c108dce79n%40googlegroups.com.

Reply via email to