From 97d5363e2b2aee456edc5db4b5b53316c8b40745 Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Fri, 13 Dec 2019 18:19:23 -0500 Subject: [PATCH] fix(build): Remove async ready (#185) * fix(build): Remove async ready * fix build --- tonic-build/src/client.rs | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/tonic-build/src/client.rs b/tonic-build/src/client.rs index 20b5f7ec7..bd83c14e6 100644 --- a/tonic-build/src/client.rs +++ b/tonic-build/src/client.rs @@ -34,13 +34,6 @@ pub(crate) fn generate(service: &Service, proto: &str) -> TokenStream { Self { inner } } - /// Check if the service is ready. - pub async fn ready(&mut self) -> Result<(), tonic::Status> { - self.inner.ready().await.map_err(|e| { - tonic::Status::new(tonic::Code::Unknown, format!("Service was not ready: {}", e.into())) - }) - } - #methods } @@ -110,7 +103,9 @@ fn generate_unary(method: &Method, proto: &str, path: String) -> TokenStream { &mut self, request: impl tonic::IntoRequest<#request>, ) -> Result, tonic::Status> { - self.ready().await?; + self.inner.ready().await.map_err(|e| { + tonic::Status::new(tonic::Code::Unknown, format!("Service was not ready: {}", e.into())) + })?; let codec = tonic::codec::ProstCodec::default(); let path = http::uri::PathAndQuery::from_static(#path); self.inner.unary(request.into_request(), path, codec).await @@ -128,7 +123,9 @@ fn generate_server_streaming(method: &Method, proto: &str, path: String) -> Toke &mut self, request: impl tonic::IntoRequest<#request>, ) -> Result>, tonic::Status> { - self.ready().await?; + self.inner.ready().await.map_err(|e| { + tonic::Status::new(tonic::Code::Unknown, format!("Service was not ready: {}", e.into())) + })?; let codec = tonic::codec::ProstCodec::default(); let path = http::uri::PathAndQuery::from_static(#path); self.inner.server_streaming(request.into_request(), path, codec).await @@ -146,10 +143,12 @@ fn generate_client_streaming(method: &Method, proto: &str, path: String) -> Toke &mut self, request: impl tonic::IntoStreamingRequest ) -> Result, tonic::Status> { - self.ready().await?; - let codec = tonic::codec::ProstCodec::default(); - let path = http::uri::PathAndQuery::from_static(#path); - self.inner.client_streaming(request.into_streaming_request(), path, codec).await + self.inner.ready().await.map_err(|e| { + tonic::Status::new(tonic::Code::Unknown, format!("Service was not ready: {}", e.into())) + })?; + let codec = tonic::codec::ProstCodec::default(); + let path = http::uri::PathAndQuery::from_static(#path); + self.inner.client_streaming(request.into_streaming_request(), path, codec).await } } } @@ -164,7 +163,9 @@ fn generate_streaming(method: &Method, proto: &str, path: String) -> TokenStream &mut self, request: impl tonic::IntoStreamingRequest ) -> Result>, tonic::Status> { - self.ready().await?; + self.inner.ready().await.map_err(|e| { + tonic::Status::new(tonic::Code::Unknown, format!("Service was not ready: {}", e.into())) + })?; let codec = tonic::codec::ProstCodec::default(); let path = http::uri::PathAndQuery::from_static(#path); self.inner.streaming(request.into_streaming_request(), path, codec).await