feat(transport): Change channel connect to be async (#107)
This makes it so you can check if the initial connection is established. Before this we used reconnect which would lazily attempt to connect. So if you were trying to connect to a non existant Server you wouldn't find out until after you attempted your first RPC. This simplifies everything by allowing you connect before creating the RPC client. BREAKING CHANGE: `Endpoint::channel` was removed in favor of an async `Endpoint::connect`.
This commit is contained in:
@@ -54,12 +54,13 @@ fn generate_connect(service_ident: &syn::Ident) -> TokenStream {
|
||||
quote! {
|
||||
impl #service_ident<tonic::transport::Channel> {
|
||||
/// Attempt to create a new client by connecting to a given endpoint.
|
||||
pub fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
|
||||
pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
|
||||
where
|
||||
D: std::convert::TryInto<tonic::transport::Endpoint>,
|
||||
D::Error: Into<StdError>,
|
||||
{
|
||||
tonic::transport::Endpoint::new(dst).map(|c| Self::new(c.channel()))
|
||||
let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
|
||||
Ok(Self::new(conn))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user