pub struct ClientPool { /* private fields */ }Expand description
Single-threaded async HTTP client pool.
Pre-allocated slots with LIFO acquire for cache locality. Each slot
owns a RequestWriter, ResponseReader, and
HttpConnection.
§Usage
let pool = ClientPool::builder()
.url("https://api.binance.com")
.base_path("/api/v3")
.default_header("X-API-KEY", &key)?
.connections(4)
.tls(&tls)
.build()
.await?;
// Fast path (trading) — no reconnect, no wait
let mut slot = pool.try_acquire().unwrap();
// Patient path (background) — waits, reconnects with backoff
let mut slot = pool.acquire().await?;
let s: &mut ClientSlot = &mut slot;
let req = s.writer.post("/order").body(json).finish()?;
let conn = s.conn.as_mut().unwrap();
let resp = conn.send(req, &mut s.reader).await?;
// drop(slot) returns to poolImplementations§
Source§impl ClientPool
impl ClientPool
Sourcepub fn builder() -> ClientPoolBuilder
pub fn builder() -> ClientPoolBuilder
Create a builder.
Sourcepub fn try_acquire(&self) -> Option<Pooled<ClientSlot>>
pub fn try_acquire(&self) -> Option<Pooled<ClientSlot>>
Try to acquire a healthy client slot (LIFO).
Checks available slots for a healthy connection. Dead slots are ejected from the pool and a reconnect task is spawned for each. When reconnection succeeds, the slot returns to the pool automatically.
Returns None if all slots are in use or currently reconnecting.
This is the trading hot path — O(1) when the top slot is healthy.
Sourcepub async fn acquire(&self) -> Result<Pooled<ClientSlot>, RestError>
pub async fn acquire(&self) -> Result<Pooled<ClientSlot>, RestError>
Acquire a client slot, waiting until one is available.
If no healthy slots are available, waits for reconnect tasks to finish healing dead connections. Returns error if no slot becomes available within the retry limit.
This is the off-hot-path API for background tasks and REST calls.