Skip to main content

ResourcePool

Struct ResourcePool 

Source
pub struct ResourcePool { /* private fields */ }
Expand description

One (ResourceKey, generation) map for the lifetime of one session. Owns lazy init, refcount transitions, and the close trigger.

The pool is Send + Sync and intended to be held in an Arc from the session root (executor’s ExecCtx or equivalent). Each phase activation calls [ResourcePool::attach] for the adapter names it needs; the returned AttachGuard holds a clone of the per-phase DriverAdapter shell and detaches on drop.

Implementations§

Source§

impl ResourcePool

Source

pub fn new() -> Self

Source

pub fn total_attaches(&self) -> usize

Total attach count since pool construction. Useful for tests and post-mortem diagnostics.

Source

pub fn live_entries(&self) -> usize

Number of distinct entries currently live in the pool. One per (key, generation) that’s been attached at least once and not yet fully drained.

Source

pub async fn shutdown(self: &Arc<Self>)

Drain every live entry, awaiting each resource’s close() and removing the entry from the map. Call at session end so Shared-policy entries — which the per-attach detach intentionally keeps alive across phases — release their network resources before the process exits.

Emits resource.close.started reason=session-end per entry, then resource.close.completed / resource.close.failed after each resource’s close() future resolves. Returns Ok(()) even if individual close calls fail — the failures are logged and accounted, but the pool always finishes the drain so the executor can move on.

Source

pub fn declare_pending_use(&self, key: ResourceKey, policy: ResourceSharePolicy)

SRD-35 Push D: declare a predicted future attach for key under policy. Called by the pre-map walker once per phase that will eventually attach this key — the per-key counter accumulates so a Shared entry attached by 50 phases starts the run with pending_uses = 50. Each attach decrements eagerly; the entry’s close trigger fires the moment pending == 0 && live == 0, releasing the resource the instant its last user is done rather than holding it until session end.

Idempotent for a given (key, policy) — the entry is created on first call, then increments on subsequent calls. The pre-map walker is the only declared caller; adapters never invoke this directly.

Source

pub fn complete_pending_use(&self, key: &ResourceKey) -> bool

SRD-35 Push D: explicit per-key pending_uses decrement, mirroring Self::declare_pending_use. Most callers don’t need this — the AttachGuard detach path already decrements via the attach-time “slot consumed” semantic, and the close trigger observes the resulting pending == 0 && live == 0 invariant. Provided so external callers (tests, future pre-map invalidation paths) can adjust the counter explicitly. Saturating at 0 — calling this on a key with no pending uses left is a no-op, not an underflow.

Returns true when the call drove pending to 0 AND live was already 0 (so the entry was eligible for close). Doesn’t itself trigger close — the close path runs on detach. Tests that exercise the counter-only lifecycle use the return to assert the “eligible for close” gate without setting up a real attach.

Source

pub fn pending_uses_for(&self, key: &ResourceKey) -> Option<usize>

SRD-35 Push D introspection helper: how many predicted future attaches remain on the entry for key (gen 0). Returns None when no entry exists for the key. Tests use this to assert pre-map walker correctness without poking the pool internals.

Trait Implementations§

Source§

impl Default for ResourcePool

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more