pub struct ClientPool<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 ClientPool 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: ClientFacts, P: ClientTransport> ClientPool<F, P>
impl<F: ClientFacts, P: ClientTransport> ClientPool<F, P>
pub fn new<RT: AsyncRuntime + Clone>( facts: Arc<F>, rt: &RT, addr: &str, channel_size: usize, ) -> Self
pub fn is_healthy(&self) -> bool
pub fn get_addr(&self) -> &str
pub async fn send_req(&self, task: F::Task)
pub fn send_req_blocking(&self, task: F::Task)
Sourcepub fn spawn<RT: AsyncRuntime + Clone>(&self, rt: &RT)
pub fn spawn<RT: AsyncRuntime + Clone>(&self, rt: &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: ClientFacts, P: ClientTransport> ClientCaller for ClientPool<F, P>
impl<F: ClientFacts, P: ClientTransport> ClientCaller for ClientPool<F, P>
Source§impl<F: ClientFacts, P: ClientTransport> ClientCallerBlocking for ClientPool<F, P>
impl<F: ClientFacts, P: ClientTransport> ClientCallerBlocking for ClientPool<F, P>
Source§impl<F: ClientFacts, P: ClientTransport> Clone for ClientPool<F, P>
impl<F: ClientFacts, P: ClientTransport> Clone for ClientPool<F, P>
Auto Trait Implementations§
impl<F, P> !Freeze for ClientPool<F, P>
impl<F, P> !RefUnwindSafe for ClientPool<F, P>
impl<F, P> Send for ClientPool<F, P>
impl<F, P> Sync for ClientPool<F, P>
impl<F, P> Unpin for ClientPool<F, P>
impl<F, P> UnsafeUnpin for ClientPool<F, P>
impl<F, P> !UnwindSafe for ClientPool<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