pub struct RuntimePool { /* private fields */ }Expand description
A fixed pool of Runtimes over an MPMC channel.
A request checks a runtime out with get() and uses it
exclusively; the returned RuntimeGuard sends it back on drop. When all
runtimes are busy, get() waits fairly (FIFO) — the channel is the
backpressure mechanism — and
get_timeout() bounds that wait so an overloaded
server sheds load instead of queueing without limit.
Implementations§
Source§impl RuntimePool
impl RuntimePool
Sourcepub fn with_rebuild<F>(runtimes: Vec<Runtime>, rebuild: F) -> Self
pub fn with_rebuild<F>(runtimes: Vec<Runtime>, rebuild: F) -> Self
Creates a pool that recycles damaged states: when a request leaves a
state poisoned (memory limit hit, panic), it is dropped and rebuild
produces a fresh one so capacity is restored.
Sourcepub fn with_companion<T: Any + Send + Sync>(self, companion: T) -> Self
pub fn with_companion<T: Any + Send + Sync>(self, companion: T) -> Self
Keeps companion with this pool, readable with
companion().
Sourcepub fn companion<T: Any + Send + Sync>(&self) -> Option<&T>
pub fn companion<T: Any + Send + Sync>(&self) -> Option<&T>
The companion set with with_companion(),
when it is a T.
Sourcepub async fn get(&self) -> RuntimeGuard
pub async fn get(&self) -> RuntimeGuard
Checks a runtime out of the pool, waiting until one is available.
Sourcepub async fn get_timeout(&self, wait: Duration) -> Option<RuntimeGuard>
pub async fn get_timeout(&self, wait: Duration) -> Option<RuntimeGuard>
Checks a runtime out, giving up after wait.
Returns None when no state became available in time, so the caller
can shed the request (503) instead of letting it queue behind an
overloaded pool. A zero duration disables the bound and waits like
get().
Trait Implementations§
Source§impl Clone for RuntimePool
impl Clone for RuntimePool
Auto Trait Implementations§
impl !RefUnwindSafe for RuntimePool
impl !Unpin for RuntimePool
impl !UnsafeUnpin for RuntimePool
impl !UnwindSafe for RuntimePool
impl Freeze for RuntimePool
impl Send for RuntimePool
impl Sync for RuntimePool
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> 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 more