gRPC C++ callback API

1,649 views
Skip to first unread message

Rohit Zambre

unread,
Oct 12, 2022, 6:13:35 PM10/12/22
to grpc.io
Hi,

Is it possible to use the callback API without calling server->Wait()?

In the route_guide example, I see that route_guide_callback_sever.cc calls server->Wait(). In my use case, I cannot block on a call like Wait().

Regards,
Rohit

AJ Heller

unread,
Oct 19, 2022, 2:36:33 PM10/19/22
to grpc.io
That's fine. You can replace the Wait call with `absl::SleepFor(absl::Seconds(42))` and it should work fine since the callback API does not need to borrow threads from the application. At shutdown, you'll still may want to wait on the gRPC server to finish doing its job before exiting, but that's a separate matter.

Rohit Zambre

unread,
Oct 20, 2022, 8:03:26 PM10/20/22
to AJ Heller, grpc.io
Got it, thank you.

This may be an orthogonal question -- does the async API (polling for events on the completion queue) steal from the application's threads? In other words, is the gRPC runtime running in the background even in the async API?
I have been using the async API under the assumption that the gRPC engine is not invoked (except for accepting new connection requests) until I call Next() or AsyncNext() on a completion queue.

--
You received this message because you are subscribed to a topic in the Google Groups "grpc.io" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/grpc-io/hnQ60W6hPMA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to grpc-io+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/95ef746c-dd34-4a14-b7be-c10e9930e1can%40googlegroups.com.

AJ Heller

unread,
Oct 21, 2022, 3:25:51 PM10/21/22
to grpc.io
That's correct. You can read more about the async API here https://grpc.io/docs/languages/cpp/async/, specifically where it says you have to call `Next` to poll for events. The callback API leverages gRPC-internal threads to execute application-provided callbacks. The callback API is described in more detail here: https://github.com/grpc/proposal/blob/master/L67-cpp-callback-api.md
Reply all
Reply to author
Forward
0 new messages