pub struct KeyedPool<K, A, E = Never, R = HNil> { /* private fields */ }Expand description
A pool partitioned by key: each key has its own Pool of capacity items, created on
first use (Effect.ts KeyedPool). Checking out under one key never waits on another.
use id_effect::Exit;
use id_effect::{Effect, KeyedPool, succeed};
use id_effect::Never;
let pool: KeyedPool<&str, String> = KeyedPool::new(1, |k: &str| succeed(format!("conn-{k}")));
let p = pool.clone();
let eff: Effect<(String, String), Never> =
Effect::scoped(move |scope| p.get("a", &scope).zip(p.get("b", &scope)));
assert!(matches!(eff.block_on(), Exit::Success((a, b)) if a == "conn-a" && b == "conn-b"));Implementations§
Source§impl<K, A, E, R> KeyedPool<K, A, E, R>
impl<K, A, E, R> KeyedPool<K, A, E, R>
Sourcepub fn new(
capacity: usize,
acquire: impl Fn(K) -> Effect<A, E, R> + Send + Sync + 'static,
) -> Self
pub fn new( capacity: usize, acquire: impl Fn(K) -> Effect<A, E, R> + Send + Sync + 'static, ) -> Self
A keyed pool with capacity items per key; acquire(key) builds a new item for a key.
A plain constructor: nothing is acquired until the first checkout.
Sourcepub fn new_with(
capacity: impl Fn(&K) -> usize + Send + Sync + 'static,
acquire: impl Fn(K) -> Effect<A, E, R> + Send + Sync + 'static,
) -> Self
pub fn new_with( capacity: impl Fn(&K) -> usize + Send + Sync + 'static, acquire: impl Fn(K) -> Effect<A, E, R> + Send + Sync + 'static, ) -> Self
A keyed pool whose per-key capacity is capacity(&key) (Effect.ts KeyedPool.makeWith).
Sourcepub fn with_release(
self,
release: impl Fn(A) -> Effect<(), Never, HNil> + Send + Sync + 'static,
) -> Self
pub fn with_release( self, release: impl Fn(A) -> Effect<(), Never, HNil> + Send + Sync + 'static, ) -> Self
See Pool::with_release; applies to every key. Configure before the first checkout.
Sourcepub fn with_ttl(self, ttl: Duration) -> Self
pub fn with_ttl(self, ttl: Duration) -> Self
See Pool::with_ttl; applies to every key. Configure before the first checkout.
Sourcepub fn get(&self, key: K, scope: &Scope) -> Effect<A, E, R>
pub fn get(&self, key: K, scope: &Scope) -> Effect<A, E, R>
Checks an item for key out into scope; see Pool::get.
Sourcepub fn invalidate<E2: Send + 'static, R2: Send + Sync + 'static>(
&self,
key: &K,
item: &A,
) -> Effect<(), E2, R2>
pub fn invalidate<E2: Send + 'static, R2: Send + Sync + 'static>( &self, key: &K, item: &A, ) -> Effect<(), E2, R2>
Marks item of key as unusable; see Pool::invalidate.
Sourcepub fn idle_count(&self, key: &K) -> usize
pub fn idle_count(&self, key: &K) -> usize
Idle items of key.
Trait Implementations§
Auto Trait Implementations§
impl<K, A, E = !, R = HNil> !RefUnwindSafe for KeyedPool<K, A, E, R>
impl<K, A, E = !, R = HNil> !UnwindSafe for KeyedPool<K, A, E, R>
impl<K, A, E, R> Freeze for KeyedPool<K, A, E, R>
impl<K, A, E, R> Send for KeyedPool<K, A, E, R>
impl<K, A, E, R> Sync for KeyedPool<K, A, E, R>
impl<K, A, E, R> Unpin for KeyedPool<K, A, E, R>
impl<K, A, E, R> UnsafeUnpin for KeyedPool<K, A, E, R>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> ⓘ
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 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> ⓘ
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