Skip to main content

KeyedPool

Struct KeyedPool 

Source
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>
where K: Clone + Eq + Hash + Send + Sync + 'static, A: Clone + PartialEq + Send + 'static, E: Send + 'static, R: Send + Sync + 'static,

Source

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.

Source

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).

Source

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.

Source

pub fn with_ttl(self, ttl: Duration) -> Self

See Pool::with_ttl; applies to every key. Configure before the first checkout.

Source

pub fn get(&self, key: K, scope: &Scope) -> Effect<A, E, R>

Checks an item for key out into scope; see Pool::get.

Source

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.

Source

pub fn in_use(&self, key: &K) -> usize

Items of key currently checked out.

Source

pub fn idle_count(&self, key: &K) -> usize

Idle items of key.

Source

pub fn shutdown(&self) -> Effect<(), Never, HNil>

Shuts every key’s pool down; see Pool::shutdown. Later checkouts are interrupted.

Trait Implementations§

Source§

impl<K, A, E, R> Clone for KeyedPool<K, A, E, R>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K, A, E, R> Debug for KeyedPool<K, A, E, R>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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>
where Arc<Mutex<KeyedState<K, A, E, R>>>: Freeze, Arc<dyn Fn(&K) -> usize + Sync + Send>: Freeze, Arc<dyn Fn(K) -> Effect<A, E, R> + Sync + Send>: Freeze, Option<Arc<dyn Fn(A) -> Effect<()> + Sync + Send>>: Freeze,

§

impl<K, A, E, R> Send for KeyedPool<K, A, E, R>
where Arc<Mutex<KeyedState<K, A, E, R>>>: Send, Arc<dyn Fn(&K) -> usize + Sync + Send>: Send, Arc<dyn Fn(K) -> Effect<A, E, R> + Sync + Send>: Send, Option<Arc<dyn Fn(A) -> Effect<()> + Sync + Send>>: Send,

§

impl<K, A, E, R> Sync for KeyedPool<K, A, E, R>
where Arc<Mutex<KeyedState<K, A, E, R>>>: Sync, Arc<dyn Fn(&K) -> usize + Sync + Send>: Sync, Arc<dyn Fn(K) -> Effect<A, E, R> + Sync + Send>: Sync, Option<Arc<dyn Fn(A) -> Effect<()> + Sync + Send>>: Sync,

§

impl<K, A, E, R> Unpin for KeyedPool<K, A, E, R>
where Arc<Mutex<KeyedState<K, A, E, R>>>: Unpin, Arc<dyn Fn(&K) -> usize + Sync + Send>: Unpin, Arc<dyn Fn(K) -> Effect<A, E, R> + Sync + Send>: Unpin, Option<Arc<dyn Fn(A) -> Effect<()> + Sync + Send>>: Unpin,

§

impl<K, A, E, R> UnsafeUnpin for KeyedPool<K, A, E, R>
where Arc<Mutex<KeyedState<K, A, E, R>>>: UnsafeUnpin, Arc<dyn Fn(&K) -> usize + Sync + Send>: UnsafeUnpin, Arc<dyn Fn(K) -> Effect<A, E, R> + Sync + Send>: UnsafeUnpin, Option<Arc<dyn Fn(A) -> Effect<()> + Sync + Send>>: UnsafeUnpin,

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<S> Embed<HNil, HNil> for S

Source§

fn project(&self) -> HNil

The sub-environment.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Pipe for T

Source§

fn pipe<F, R>(self, f: F) -> R
where F: FnOnce(Self) -> R,

Applies f to self (F#-style forward pipe).
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.