Skip to content

Commit

Permalink
feat(transport): Add connect_with_connector_lazy (#696)
Browse files Browse the repository at this point in the history
Closes #695
  • Loading branch information
LucioFranco authored Jul 1, 2021
1 parent 737ace3 commit 2a46ff5
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tonic/src/transport/channel/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,27 @@ impl Endpoint {
}
}

/// Connect with a custom connector lazily.
///
/// This allows you to build a [Channel](struct.Channel.html) that uses a non-HTTP transport.
/// See the `uds` example for an example on how to use this function to build channel that
/// uses a Unix socket transport.
pub async fn connect_with_connector_lazy<C>(&self, connector: C) -> Result<Channel, Error>
where
C: MakeConnection<Uri> + Send + 'static,
C::Connection: Unpin + Send + 'static,
C::Future: Send + 'static,
crate::Error: From<C::Error> + Send + 'static,
{
#[cfg(feature = "tls")]
let connector = service::connector(connector, self.tls.clone());

#[cfg(not(feature = "tls"))]
let connector = service::connector(connector);

Ok(Channel::new(connector, self.clone()))
}

/// Get the endpoint uri.
///
/// ```
Expand Down

0 comments on commit 2a46ff5

Please sign in to comment.