pub struct ConnPool<C> { /* private fields */ }Expand description
Outbound connection pool.
The pool keeps an AutoEject tracker and a small idle list;
callers acquire a connection through ConnPool::get and
return it through ConnHandle::release (or by dropping the
handle, which routes to the same path).
Implementations§
Source§impl<C: Send + 'static> ConnPool<C>
impl<C: Send + 'static> ConnPool<C>
Sourcepub fn new(cfg: ConnPoolConfig) -> Self
pub fn new(cfg: ConnPoolConfig) -> Self
Build a pool with no factory installed. Build a pool with no factory installed.
Callers must install a factory through
ConnPool::set_factory before invoking
ConnPool::get. The factory-less constructor exists so
callers can build the pool eagerly during configuration and
wire the factory once the resolver has populated the target
address.
§Examples
use dynomite::io::reactor::TcpTransport;
use dynomite::net::pool::{ConnPool, ConnPoolConfig};
let _: ConnPool<TcpTransport> = ConnPool::new(ConnPoolConfig::default());Sourcepub fn with_factory<F>(cfg: ConnPoolConfig, factory: F) -> Selfwhere
F: ConnFactory<C>,
pub fn with_factory<F>(cfg: ConnPoolConfig, factory: F) -> Selfwhere
F: ConnFactory<C>,
Build a pool with a factory installed up front.
§Examples
use dynomite::net::pool::{ConnPool, ConnPoolConfig};
use dynomite::net::NetError;
let pool = ConnPool::with_factory(ConnPoolConfig::default(), || async {
Ok::<u32, NetError>(0)
});
assert_eq!(pool.config().max_connections, 1);Sourcepub fn set_factory<F: ConnFactory<C>>(&mut self, factory: F)
pub fn set_factory<F: ConnFactory<C>>(&mut self, factory: F)
Install a connection factory.
Sourcepub fn config(&self) -> ConnPoolConfig
pub fn config(&self) -> ConnPoolConfig
Borrow the pool config.
Sourcepub fn idle_count(&self) -> usize
pub fn idle_count(&self) -> usize
Number of idle connections currently in the pool.
Sourcepub fn is_ejected(&self, now: Instant) -> bool
pub fn is_ejected(&self, now: Instant) -> bool
True when the host has been auto-ejected at this instant.
Sourcepub fn auto_eject(&self) -> AutoEject
pub fn auto_eject(&self) -> AutoEject
Snapshot of the auto-eject tracker.
Sourcepub fn shutdown(&self)
pub fn shutdown(&self)
Shut the pool down.
Wakes every waiter blocked in ConnPool::get. Subsequent
get calls return NetError::PoolShutdown.
Sourcepub async fn get(&self) -> Result<ConnHandle<C>, NetError>
pub async fn get(&self) -> Result<ConnHandle<C>, NetError>
Acquire a connection.
Reuses an idle connection when one is available; otherwise invokes the factory until it succeeds or the auto-eject tracker reports the target as unreachable.
§Errors
Returns NetError::Ejected when the host is in its eject
window, NetError::PoolShutdown when the pool was shut
down, or the underlying factory error otherwise.
Trait Implementations§
Auto Trait Implementations§
impl<C> Freeze for ConnPool<C>
impl<C> !RefUnwindSafe for ConnPool<C>
impl<C> Send for ConnPool<C>where
C: Send,
impl<C> Sync for ConnPool<C>where
C: Send,
impl<C> Unpin for ConnPool<C>
impl<C> UnsafeUnpin for ConnPool<C>
impl<C> !UnwindSafe for ConnPool<C>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.