Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make pub Channel fns that allow creating it from a custom connector #2015

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions tonic/src/transport/channel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use http::{
uri::{InvalidUri, Uri},
Request, Response,
};
use hyper_util::client::legacy::connect::Connection as HyperConnection;
use std::{
fmt,
future::Future,
Expand Down Expand Up @@ -145,12 +144,15 @@ impl Channel {
(Self::balance(list, DEFAULT_BUFFER_SIZE, executor), tx)
}

pub(crate) fn new<C>(connector: C, endpoint: Endpoint) -> Self
/// Create a new [`Channel`] using a custom connector to the provided [Endpoint].
///
/// This is a lower level API, prefer to use [`Endpoint::connect_lazy`] if you are not using a custom connector.
pub fn new<C>(connector: C, endpoint: Endpoint) -> Self
where
C: Service<Uri> + Send + 'static,
C::Error: Into<crate::Error> + Send,
C::Future: Send,
C::Response: rt::Read + rt::Write + HyperConnection + Unpin + Send + 'static,
C::Response: rt::Read + rt::Write + Unpin + Send + 'static,
{
let buffer_size = endpoint.buffer_size.unwrap_or(DEFAULT_BUFFER_SIZE);
let executor = endpoint.executor.clone();
Expand All @@ -162,12 +164,15 @@ impl Channel {
Channel { svc }
}

pub(crate) async fn connect<C>(connector: C, endpoint: Endpoint) -> Result<Self, super::Error>
/// Connect to the provided [`Endpoint`] using the provided connector, and return a new [`Channel`].
///
/// This is a lower level API, prefer to use [`Endpoint::connect`] if you are not using a custom connector.
pub async fn connect<C>(connector: C, endpoint: Endpoint) -> Result<Self, super::Error>
where
C: Service<Uri> + Send + 'static,
C::Error: Into<crate::Error> + Send,
C::Future: Unpin + Send,
C::Response: rt::Read + rt::Write + HyperConnection + Unpin + Send + 'static,
C::Response: rt::Read + rt::Write + Unpin + Send + 'static,
{
let buffer_size = endpoint.buffer_size.unwrap_or(DEFAULT_BUFFER_SIZE);
let executor = endpoint.executor.clone();
Expand Down