use crate::{
cmap::{options::ConnectionPoolOptions, Connection, ConnectionPool},
error::Result,
options::{ClientOptions, StreamAddress},
runtime::HttpClient,
};
#[derive(Debug)]
pub(crate) struct Server {
pub(crate) address: StreamAddress,
pool: ConnectionPool,
}
impl Server {
pub(crate) fn new(
address: StreamAddress,
options: &ClientOptions,
http_client: HttpClient,
) -> Self {
Self {
pool: ConnectionPool::new(
address.clone(),
http_client,
Some(ConnectionPoolOptions::from_client_options(options)),
),
address,
}
}
pub(crate) async fn checkout_connection(&self) -> Result<Connection> {
self.pool.check_out().await
}
pub(crate) async fn clear_connection_pool(&self) {
self.pool.clear().await;
}
}