Skip to main content

ClientPool

Struct ClientPool 

Source
pub struct ClientPool { /* private fields */ }
Expand description

A small pool of connections to one service, for callers that hold connections across calls (a Client carries one request at a time). Connections open lazily through the caller’s connect source — the same shape Client::call_retrying_over takes, so host verification stays the caller’s — and a healthy one is reused for the next call. A client known closed (Client::is_closed) is discarded before a request is spent on it, and one that closes or times out during a call is discarded after it. Retries follow the same deadline rules as Client::call_retrying: a retryable connect failure is retried within policy, and a written request is resubmitted only on host handoff, or on close/timeout when policy.idempotent says it may run twice.

Implementations§

Source§

impl ClientPool

Source

pub fn new<F>(size: usize, connect: F) -> Self
where F: Fn(Option<Duration>) -> Result<Client, ConnectError> + Send + Sync + 'static,

A pool of size connections (at least one), opened by connect, which receives the per-attempt deadline from the RetryPolicy of each call.

Source

pub fn discard_all(&self)

Drop every pooled connection (the host was replaced, so each points at a dead process). The next call on each slot reconnects instead of spending its one attempt on a closed connection.

Source

pub fn call(&self, method: &str, params: Value) -> Result<Value, ServiceError>

Call method on a pooled connection under the default RetryPolicy (not idempotent: a request that may have run is never resent).

Source

pub fn call_with_policy( &self, method: &str, params: Value, policy: RetryPolicy, on_event: &mut dyn FnMut(&Value), ) -> Result<Value, ServiceError>

call with an explicit retry policy and event sink. Requests go through Client::call_large, so oversize requests/results chunk as usual.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.