From 76de87eec543ee712acdd1f55f08c9c6c20d2a8e Mon Sep 17 00:00:00 2001 From: Akhil Velagapudi Date: Tue, 5 Jan 2021 16:02:13 -0500 Subject: [PATCH] Remove unnecessary dependencies in tonic-health (#502) * remove dependency on bytes * remove dependency on async-stream --- tonic-health/Cargo.toml | 2 -- tonic-health/src/server.rs | 15 ++++++--------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/tonic-health/Cargo.toml b/tonic-health/Cargo.toml index a27306c..e7de702 100644 --- a/tonic-health/Cargo.toml +++ b/tonic-health/Cargo.toml @@ -18,10 +18,8 @@ default = ["transport"] transport = ["tonic/transport"] [dependencies] -async-stream = "0.2" tokio = { version = "0.2", features = ["sync", "stream"] } tonic = { version = "0.3", path = "../tonic", features = ["codegen", "prost"] } -bytes = "0.5" prost = "0.6" [dev-dependencies] diff --git a/tonic-health/src/server.rs b/tonic-health/src/server.rs index c2837f7..1547b8d 100644 --- a/tonic-health/src/server.rs +++ b/tonic-health/src/server.rs @@ -6,7 +6,7 @@ use crate::ServingStatus; use std::collections::HashMap; use std::pin::Pin; use std::sync::Arc; -use tokio::stream::Stream; +use tokio::stream::{Stream, StreamExt}; use tokio::sync::{watch, RwLock}; #[cfg(feature = "transport")] use tonic::transport::NamedService; @@ -148,18 +148,15 @@ impl Health for HealthService { request: Request, ) -> Result, Status> { let service_name = request.get_ref().service.as_str(); - let mut status_rx = match self.statuses.read().await.get(service_name) { + let status_rx = match self.statuses.read().await.get(service_name) { None => return Err(Status::not_found("service not registered")), Some(pair) => pair.1.clone(), }; - let output = async_stream::try_stream! { - while let Some(status) = status_rx.recv().await { - yield HealthCheckResponse{ - status: crate::proto::health_check_response::ServingStatus::from(status) as i32, - }; - } - }; + let output = status_rx.map(|status| { + let status = crate::proto::health_check_response::ServingStatus::from(status) as i32; + Ok(HealthCheckResponse { status }) + }); Ok(Response::new(Box::pin(output) as Self::WatchStream)) }