pub struct ConnPool<F, P>where
F: ClientFacts,
P: ClientTransport,{ /* private fields */ }Expand description
Connection pool to the one server address (supports async and blocking context)
There’s a worker accepting task post in bounded channel.
Even when the server address is not reachable, the worker coroutine will not exit, until ConnPool is dropped.
The background coroutine will:
- monitor the address with ping task (action 0)
- cleanup the task in channel with error_handle when the address is unhealthy
If the connection is healthy and there’s incoming, the worker will spawn another coroutine for monitor purpose.
considering:
- The task incoming might never stop until faulty pool remove from pools collection
- If ping mixed with task with real business, might blocked due to throttler of in-flight message in the stream.
Implementations§
Source§impl<F, P> ConnPool<F, P>where
F: ClientFacts,
P: ClientTransport,
impl<F, P> ConnPool<F, P>where
F: ClientFacts,
P: ClientTransport,
pub fn new( facts: Arc<F>, rt: &<P as ClientTransport>::RT, addr: &str, channel_size: usize, ) -> ConnPool<F, P>
pub fn is_healthy(&self) -> bool
pub fn get_addr(&self) -> &str
pub async fn send_req(&self, task: <F as ClientFacts>::Task)
pub fn send_req_blocking(&self, task: <F as ClientFacts>::Task)
Sourcepub fn spawn(&self, rt: &<P as ClientTransport>::RT)
pub fn spawn(&self, rt: &<P as ClientTransport>::RT)
by default there’s one worker thread after initiation, but you can pre-spawn more thread if the connection is not enough to achieve desired throughput.
Trait Implementations§
Source§impl<F, P> APIClientCaller for ConnPool<F, P>
impl<F, P> APIClientCaller for ConnPool<F, P>
Source§impl<F, P> ClientCaller for ConnPool<F, P>where
F: ClientFacts,
P: ClientTransport,
impl<F, P> ClientCaller for ConnPool<F, P>where
F: ClientFacts,
P: ClientTransport,
Source§impl<F, P> ClientCallerBlocking for ConnPool<F, P>where
F: ClientFacts,
P: ClientTransport,
impl<F, P> ClientCallerBlocking for ConnPool<F, P>where
F: ClientFacts,
P: ClientTransport,
type Facts = F
fn send_req_blocking(&self, task: <F as ClientFacts>::Task)
fn get_codec(&self) -> <Self::Facts as ClientFacts>::Codec
Source§impl<F, P> Clone for ConnPool<F, P>where
F: ClientFacts,
P: ClientTransport,
impl<F, P> Clone for ConnPool<F, P>where
F: ClientFacts,
P: ClientTransport,
Auto Trait Implementations§
impl<F, P> !Freeze for ConnPool<F, P>
impl<F, P> !RefUnwindSafe for ConnPool<F, P>
impl<F, P> Send for ConnPool<F, P>
impl<F, P> Sync for ConnPool<F, P>
impl<F, P> Unpin for ConnPool<F, P>
impl<F, P> UnsafeUnpin for ConnPool<F, P>
impl<F, P> !UnwindSafe for ConnPool<F, P>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more