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:
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user