transport: impl Service for Channel instead of GrpcService (#482)

* transport: impl Service for Channel instead of GrpcService

This adds tower::Service impl for tonic::transport::Channel
and removes GrpcService impl declaration.

Channel still implements GrpcService, thanks to the general
impl declaration of GrpcService for types who implement Service.

Fixes #481.

* examples: stop using GrpcService to avoid ambiguity

* examples: add timeout example
This commit is contained in:
Koki Kato
2021-01-05 13:36:18 -05:00
committed by GitHub
parent 2b9cdb9779
commit e7be352132
5 changed files with 88 additions and 7 deletions
+7 -6
View File
@@ -10,7 +10,7 @@ pub use endpoint::Endpoint;
pub use tls::ClientTlsConfig;
use super::service::{Connection, DynamicServiceStream};
use crate::{body::BoxBody, client::GrpcService};
use crate::body::BoxBody;
use bytes::Bytes;
use http::{
uri::{InvalidUri, Uri},
@@ -177,17 +177,18 @@ impl Channel {
}
}
impl GrpcService<BoxBody> for Channel {
type ResponseBody = hyper::Body;
impl Service<http::Request<BoxBody>> for Channel {
type Response = http::Response<super::Body>;
type Error = super::Error;
type Future = ResponseFuture;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
GrpcService::poll_ready(&mut self.svc, cx).map_err(super::Error::from_source)
Service::poll_ready(&mut self.svc, cx).map_err(super::Error::from_source)
}
fn call(&mut self, request: Request<BoxBody>) -> Self::Future {
let inner = GrpcService::call(&mut self.svc, request);
fn call(&mut self, request: http::Request<BoxBody>) -> Self::Future {
let inner = Service::call(&mut self.svc, request);
ResponseFuture { inner }
}
}