pub struct Pool { /* private fields */ }Expand description
A fixed-size set of BrainClient connections handed out round-robin.
Implementations§
Source§impl Pool
impl Pool
Sourcepub async fn connect(addr: SocketAddr, size: usize, auth: Auth) -> Result<Self>
pub async fn connect(addr: SocketAddr, size: usize, auth: Auth) -> Result<Self>
Open size connections to addr with the given credential and default
transport settings, and run every handshake. Fails (closing any
already-opened members) if size is 0 or any connection’s handshake
fails.
Sourcepub async fn connect_with(
addr: SocketAddr,
size: usize,
config: &ClientConfig,
) -> Result<Self>
pub async fn connect_with( addr: SocketAddr, size: usize, config: &ClientConfig, ) -> Result<Self>
Open size connections to addr with an explicit configuration
template, cloned per connection. Each member runs its own handshake.
All members share the template’s credential, so the server binds them to
the same agent; they remain individually identifiable by session id.
Sourcepub fn get(&self) -> Arc<BrainClient> ⓘ
pub fn get(&self) -> Arc<BrainClient> ⓘ
Borrow the next connection, round-robin, as-is — it may be dead if the
server went away. Prefer Pool::get_healthy for long-lived pools.
The returned Arc is cheap to clone and safe to move across tasks; the
underlying client multiplexes concurrent requests itself.
§Panics
Only if a slot’s lock was poisoned by a panic while swapping a client.
Sourcepub async fn get_healthy(&self) -> Result<Arc<BrainClient>>
pub async fn get_healthy(&self) -> Result<Arc<BrainClient>>
Borrow the next live connection, round-robin, reconnecting it first if it has died (e.g. the server restarted). Requests already in flight on the old connection fail as before; new ones get the fresh socket.
§Errors
The reconnect’s BrainError if the server is still unreachable.
§Panics
Only if a slot’s lock was poisoned by a panic while swapping a client.