ConnectionPool

Struct ConnectionPool 

Source
pub struct ConnectionPool<Connector: ClientConnector> { /* private fields */ }
Expand description

A connection pool for protosocket rpc clients.

Protosocket-rpc connections are shared and multiplexed, so this vends cloned handles. You can hold onto a handle from the pool for as long as you want. There is a small synchronization cost to getting a handle from a pool, so caching is a good idea - but if you want to load balance a lot, you can just make a pool with as many “slots” as you want to dilute any contention on connection state locks. The locks are typically held for the time it takes to clone an Arc, so it’s usually nanosecond-scale synchronization, per connection. So if you have several connections, you’ll rarely contend.

Implementations§

Source§

impl<Connector: ClientConnector> ConnectionPool<Connector>

Source

pub fn new(connector: Connector, connection_count: usize) -> Self

Create a new connection pool.

It will try to maintain connection_count healthy connections.

Source

pub async fn get_connection( &self, ) -> Result<RpcClient<Connector::Request, Connector::Response>>

Get a connection from the pool.

Trait Implementations§

Source§

impl<Connector: Debug + ClientConnector> Debug for ConnectionPool<Connector>
where Connector::Request: Debug, Connector::Response: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Connector> Freeze for ConnectionPool<Connector>
where Connector: Freeze,

§

impl<Connector> RefUnwindSafe for ConnectionPool<Connector>
where Connector: RefUnwindSafe,

§

impl<Connector> Send for ConnectionPool<Connector>
where Connector: Send,

§

impl<Connector> Sync for ConnectionPool<Connector>
where Connector: Sync,

§

impl<Connector> Unpin for ConnectionPool<Connector>
where Connector: Unpin,

§

impl<Connector> UnwindSafe for ConnectionPool<Connector>
where Connector: UnwindSafe,

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V