C++: how to handle blocking code from callback reactor

44 views
Skip to first unread message

Shareef Jalloq

unread,
Nov 23, 2022, 12:10:10 PM11/23/22
to grpc.io
Hi,

I'm new to gRPC and am struggling to find examples of how to call application code that blocks when using the callback API.

I found the documentation here: https://github.com/grpc/proposal/blob/master/L67-cpp-callback-api.md and noted that it recommend that code in any reaction must not block.  So for an example of a simple unary reactor such as that in the route_guide_callback_server.cc, what is the correct way of handing off to your application code?

Am I correct in assuming that I need to call my blocking application code in a new thread and pass the reactor (along with req/resp) to that new thread such that it can call reactor->Finish() once the work is done?

Thanks, Shareef.

AJ Heller

unread,
Dec 1, 2022, 12:24:32 PM12/1/22
to grpc.io
> Am I correct in assuming that I need to call my blocking application code in a new thread and pass the reactor (along with req/resp) to that new thread such that it can call reactor->Finish() once the work is done?

Yes, that's the most general recommendation, which you can find further down on that same gRFC you linked to: "One way of doing this is to push that code to a separate application-controlled thread."
Reply all
Reply to author
Forward
0 new messages