grpc - asynchronous server

Please tell me about working with the grpc crate. The question is how to handle server-side rpc calls in an asynchronous manner. The handlers that protoc generates are as follows:

fn some_func(&self, o: ::grpc::ServerHandlerContext, req: ::grpc::ServerRequestSingle<super::cpth::CheckImgCaptchaRequest>, resp: ::grpc::ServerResponseUnarySink<super::cpth::CheckImgCaptchaResponse>) -> ::grpc::Result<()>;

It implies that the grpc :: Result type is returned. As far as I understand, based on the library documentation and questions on GitHub, there is some way to bring this type to Future, providing possibly asynchronous request processing as implemented in most server libraries, such as hyper, json-rpc, actix-web, etc. But I do not understand how this can be achieved.

fn some_func(&self, _: ServerHandlerContext, _req: ServerRequestSingle<CheckImgCaptchaRequest>, resp: ServerResponseUnarySink<CheckImgCaptchaResponse>) -> ::grpc::Result<()> {
        r.result = true;

       //How to complete this call with Future insead of resp.finish(r)???

From no experience my glance at example the library is using httpbis backed by tokio.

This say_hello is the result of being called inside the executor. If your after adding async functionality before finish my guess is you would change it to;

 .then(move |_| { resp.finish(r) ; ok(()) }

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.