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:
Lucio Franco
2019-10-31 14:09:40 -04:00
committed by GitHub
parent 108bad0d86
commit 5c2f4dba32
18 changed files with 243 additions and 38 deletions
+2 -1
View File
@@ -15,7 +15,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
HeaderValue::from_static("Bearer some-secret-token"),
);
})
.channel();
.connect()
.await?;
let mut client = EchoClient::new(channel);
+2 -1
View File
@@ -37,7 +37,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
headers.insert("authorization", header_value.clone());
})
.tls_config(&tls_config)
.channel();
.connect()
.await?;
let mut service = PublisherClient::new(channel);
+1 -1
View File
@@ -6,7 +6,7 @@ use hello_world::{client::GreeterClient, HelloRequest};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut client = GreeterClient::connect("http://[::1]:50051")?;
let mut client = GreeterClient::connect("http://[::1]:50051").await?;
let request = tonic::Request::new(HelloRequest {
name: "Tonic".into(),
+3 -1
View File
@@ -12,7 +12,9 @@ use tonic::transport::Endpoint;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let channel = Endpoint::from_static("http://[::1]:50051").channel();
let channel = Endpoint::from_static("http://[::1]:50051")
.connect()
.await?;
let mut greeter_client = GreeterClient::new(channel.clone());
let mut echo_client = EchoClient::new(channel);
+1 -1
View File
@@ -91,7 +91,7 @@ async fn run_route_chat(client: &mut RouteGuideClient<Channel>) -> Result<(), Bo
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut client = RouteGuideClient::connect("http://[::1]:10000")?;
let mut client = RouteGuideClient::connect("http://[::1]:10000").await?;
println!("*** SIMPLE RPC ***");
let response = client
+2 -1
View File
@@ -17,7 +17,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let channel = Channel::from_static("http://[::1]:50051")
.tls_config(&tls)
.channel();
.connect()
.await?;
let mut client = EchoClient::new(channel);
let request = tonic::Request::new(EchoRequest {
+2 -2
View File
@@ -21,8 +21,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let channel = Channel::from_static("http://[::1]:50051")
.tls_config(&tls)
.clone()
.channel();
.connect()
.await?;
let mut client = EchoClient::new(channel);