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:
@@ -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 }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user