pub struct Client { /* private fields */ }Expand description
A grpc-webnext client: a gRPC channel, not a handle to a socket.
Cheap to clone — clones share one tunnel, which is the point, since calls
multiplex over it. When that tunnel dies the channel redials on the next call,
the way tonic::transport::Channel does: the call that discovers the failure
reports it, and the one after reconnects. Watch Client::state_changes if the
application wants to say something about it.
Implementations§
Source§impl Client
impl Client
Sourcepub fn from_connection(
conn: H2Connection,
authority: impl Into<String>,
) -> Client
pub fn from_connection( conn: H2Connection, authority: impl Into<String>, ) -> Client
Build a client over an existing h2ts connection. Single-shot: there is no
way to redial, so a dropped tunnel stays dropped. Prefer
connect, which reconnects.
Sourcepub fn with_connector(
connector: Connector,
authority: impl Into<String>,
) -> Client
pub fn with_connector( connector: Connector, authority: impl Into<String>, ) -> Client
Build a reconnecting client from something that can open a tunnel on
demand. Each call to connector must yield a fresh connection, with its
driver already spawned.
Sourcepub fn over_transport(
transport: Transport,
authority: impl Into<String>,
options: ConnectOptions,
) -> (Client, impl Future<Output = ()>)
pub fn over_transport( transport: Transport, authority: impl Into<String>, options: ConnectOptions, ) -> (Client, impl Future<Output = ()>)
Build a client over any byte transport, returning the driver future the
caller must poll. Spawn it: wasm_bindgen_futures::spawn_local in a
browser, tokio::task::spawn_local on a LocalSet natively.
Single-shot, since the transport is consumed — see
from_connection.
Sourcepub fn state(&self) -> ConnectivityState
pub fn state(&self) -> ConnectivityState
The channel’s connectivity state.
Sourcepub fn state_changes(&self) -> impl Stream<Item = ConnectivityState> + 'static
pub fn state_changes(&self) -> impl Stream<Item = ConnectivityState> + 'static
Watch connectivity transitions — gRPC’s WaitForStateChange, as a stream.
Repeats are collapsed, so every item is a real change.
Sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
True if there is no usable tunnel right now. A reconnecting client will open one on the next call; a single-shot one will not.
Sourcepub async fn unary(
&self,
path: &str,
request: Vec<u8>,
options: CallOptions,
) -> Result<UnaryResponse, Status>
pub async fn unary( &self, path: &str, request: Vec<u8>, options: CallOptions, ) -> Result<UnaryResponse, Status>
Unary: one message out, one message back.
Sourcepub async fn client_streaming<S>(
&self,
path: &str,
requests: S,
options: CallOptions,
) -> Result<UnaryResponse, Status>
pub async fn client_streaming<S>( &self, path: &str, requests: S, options: CallOptions, ) -> Result<UnaryResponse, Status>
Client streaming: a stream of messages out, one message back.
The request body is uploaded as the stream yields, under HTTP/2 flow control — a slow server pushes back rather than the messages piling up here.
Sourcepub async fn server_streaming(
&self,
path: &str,
request: Vec<u8>,
options: CallOptions,
) -> Result<Streaming, Status>
pub async fn server_streaming( &self, path: &str, request: Vec<u8>, options: CallOptions, ) -> Result<Streaming, Status>
Server streaming: one message out, a stream of messages back.
Sourcepub async fn bidi_streaming<S>(
&self,
path: &str,
requests: S,
options: CallOptions,
) -> Result<Streaming, Status>
pub async fn bidi_streaming<S>( &self, path: &str, requests: S, options: CallOptions, ) -> Result<Streaming, Status>
Bidirectional streaming: a stream out, a stream back, concurrently.