Skip to content

KeyedPool

10 exports Added in v2.0.0 Source

Combinators

get

Added in v2.0.0 Source

Retrieves an item from the pool belonging to the given key in a scoped effect. Note that if acquisition fails, then the returned effect will fail for that same reason. Retrying a failed acquisition attempt will repeat the acquisition attempt.

Signature

declare const get: {
  <K>(key: K): <A, E>(self: KeyedPool<K, A, E>) => Effect<A, E, Scope>;
  <K, A, E>(self: KeyedPool<K, A, E>, key: K): Effect<A, E, Scope>;
};

invalidate

Added in v2.0.0 Source

Invalidates the specified item. This will cause the pool to eventually reallocate the item, although this reallocation may occur lazily rather than eagerly.

Signature

declare const invalidate: {
  <A>(item: A): <K, E>(self: KeyedPool<K, A, E>) => Effect<void>;
  <K, A, E>(self: KeyedPool<K, A, E>, item: A): Effect<void>;
};

Constructors

make

Added in v2.0.0 Source

Makes a new pool of the specified fixed size. The pool is returned in a Scope, which governs the lifetime of the pool. When the pool is shutdown because the Scope is closed, the individual items allocated by the pool will be released in some unspecified order.

Signature

declare const make: <K, A, E, R>(options: {
  readonly acquire: (key: K) => Effect.Effect<A, E, R>;
  readonly size: number;
}) => Effect.Effect<KeyedPool<K, A, E>, never, Scope.Scope | R>;

makeWith

Added in v2.0.0 Source

Makes a new pool of the specified fixed size. The pool is returned in a Scope, which governs the lifetime of the pool. When the pool is shutdown because the Scope is closed, the individual items allocated by the pool will be released in some unspecified order.

The size of the underlying pools can be configured per key.

Signature

declare const makeWith: <K, A, E, R>(options: {
  readonly acquire: (key: K) => Effect.Effect<A, E, R>;
  readonly size: (key: K) => number;
}) => Effect.Effect<KeyedPool<K, A, E>, never, Scope.Scope | R>;

makeWithTTL

Added in v2.0.0 Source

Makes a new pool with the specified minimum and maximum sizes and time to live before a pool whose excess items are not being used will be shrunk down to the minimum size. The pool is returned in a Scope, which governs the lifetime of the pool. When the pool is shutdown because the Scope is used, the individual items allocated by the pool will be released in some unspecified order.

The size of the underlying pools can be configured per key.

Signature

declare const makeWithTTL: <K, A, E, R>(options: {
  readonly acquire: (key: K) => Effect.Effect<A, E, R>;
  readonly max: (key: K) => number;
  readonly min: (key: K) => number;
  readonly timeToLive: Duration.DurationInput;
}) => Effect.Effect<KeyedPool<K, A, E>, never, Scope.Scope | R>;

Makes a new pool with the specified minimum and maximum sizes and time to live before a pool whose excess items are not being used will be shrunk down to the minimum size. The pool is returned in a Scope, which governs the lifetime of the pool. When the pool is shutdown because the Scope is used, the individual items allocated by the pool will be released in some unspecified order.

The size of the underlying pools can be configured per key.

Signature

declare const makeWithTTLBy: <K, A, E, R>(options: {
  readonly acquire: (key: K) => Effect.Effect<A, E, R>;
  readonly max: (key: K) => number;
  readonly min: (key: K) => number;
  readonly timeToLive: (key: K) => Duration.DurationInput;
}) => Effect.Effect<KeyedPool<K, A, E>, never, Scope.Scope | R>;

Models

KeyedPool interface

Added in v2.0.0 Source

A KeyedPool<K, A, E> is a pool of Pools of items of type A. Each pool in the KeyedPool is associated with a key of type K.

Signature

interface KeyedPool<in K, in out A, out E = never> extends Variance<K, A, E>, Pipeable {
  get(key: K): Effect<A, E, Scope>;
  invalidate(item: A): Effect<void>;
}

Other

KeyedPool

Added in v2.0.0 Source

Symbols

Signature

declare const KeyedPoolTypeId: unique symbol;

KeyedPoolTypeId type

Added in v2.0.0 Source

Signature

type KeyedPoolTypeId = typeof KeyedPoolTypeId;