<A, E, R>(options: {
readonly acquire: Effect.Effect<A, E, R>
readonly min: number
readonly max: number
readonly concurrency?: number | undefined
readonly targetUtilization?: number | undefined
readonly strategy: Strategy<A, E>
}): Effect.Effect<Pool<A, E>, never, Scope.Scope | R>Creates a scoped pool using a custom resizing and reclamation strategy.
When to use
Use to build a pool whose item lifecycle is controlled by an explicit
Strategy, such as custom background resizing, replacement, or reclamation.
Details
The returned pool requires Scope; closing the scope shuts down the pool and
releases allocated items.
export const const makeWithStrategy: <
A,
E,
R
>(options: {
readonly acquire: Effect.Effect<A, E, R>
readonly min: number
readonly max: number
readonly concurrency?: number | undefined
readonly targetUtilization?: number | undefined
readonly strategy: Strategy<A, E>
}) => Effect.Effect<
Pool<A, E>,
never,
Scope.Scope | R
>
Creates a scoped pool using a custom resizing and reclamation strategy.
When to use
Use to build a pool whose item lifecycle is controlled by an explicit
Strategy, such as custom background resizing, replacement, or reclamation.
Details
The returned pool requires Scope; closing the scope shuts down the pool and
releases allocated items.
makeWithStrategy = <function (type parameter) A in <A, E, R>(options: {
readonly acquire: Effect.Effect<A, E, R>;
readonly min: number;
readonly max: number;
readonly concurrency?: number | undefined;
readonly targetUtilization?: number | undefined;
readonly strategy: Strategy<A, E>;
}): Effect.Effect<Pool<A, E>, never, Scope.Scope | R>
A, function (type parameter) E in <A, E, R>(options: {
readonly acquire: Effect.Effect<A, E, R>;
readonly min: number;
readonly max: number;
readonly concurrency?: number | undefined;
readonly targetUtilization?: number | undefined;
readonly strategy: Strategy<A, E>;
}): Effect.Effect<Pool<A, E>, never, Scope.Scope | R>
E, function (type parameter) R in <A, E, R>(options: {
readonly acquire: Effect.Effect<A, E, R>;
readonly min: number;
readonly max: number;
readonly concurrency?: number | undefined;
readonly targetUtilization?: number | undefined;
readonly strategy: Strategy<A, E>;
}): Effect.Effect<Pool<A, E>, never, Scope.Scope | R>
R>(options: {
readonly acquire: Effect.Effect<A, E, R>
readonly min: number
readonly max: number
readonly concurrency?: number | undefined
readonly targetUtilization?: number | undefined
readonly strategy: Strategy<A, E>
}
options: {
readonly acquire: Effect.Effect<A, E, R>(property) acquire: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
acquire: import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<function (type parameter) A in <A, E, R>(options: {
readonly acquire: Effect.Effect<A, E, R>;
readonly min: number;
readonly max: number;
readonly concurrency?: number | undefined;
readonly targetUtilization?: number | undefined;
readonly strategy: Strategy<A, E>;
}): Effect.Effect<Pool<A, E>, never, Scope.Scope | R>
A, function (type parameter) E in <A, E, R>(options: {
readonly acquire: Effect.Effect<A, E, R>;
readonly min: number;
readonly max: number;
readonly concurrency?: number | undefined;
readonly targetUtilization?: number | undefined;
readonly strategy: Strategy<A, E>;
}): Effect.Effect<Pool<A, E>, never, Scope.Scope | R>
E, function (type parameter) R in <A, E, R>(options: {
readonly acquire: Effect.Effect<A, E, R>;
readonly min: number;
readonly max: number;
readonly concurrency?: number | undefined;
readonly targetUtilization?: number | undefined;
readonly strategy: Strategy<A, E>;
}): Effect.Effect<Pool<A, E>, never, Scope.Scope | R>
R>
readonly min: numbermin: number
readonly max: numbermax: number
readonly concurrency?: number | undefinedconcurrency?: number | undefined
readonly targetUtilization?: number | undefinedtargetUtilization?: number | undefined
readonly strategy: Strategy<A, E>(property) strategy: {
run: (pool: Pool<A, E>) => Effect.Effect<void>;
onAcquire: (item: PoolItem<A, E>) => Effect.Effect<void>;
reclaim: (pool: Pool<A, E>) => Effect.Effect<PoolItem<A, E> | undefined>;
}
strategy: interface Strategy<A, E>Strategy used by a Pool to manage background resizing and item
reclamation.
When to use
Use when defining a custom pool lifecycle policy that needs to run background
work, observe acquired items, or choose items for reclamation.
Details
run starts any strategy-specific background work, onAcquire is invoked
when an item is acquired, and reclaim selects an item that can be removed
or replaced.
Strategy<function (type parameter) A in <A, E, R>(options: {
readonly acquire: Effect.Effect<A, E, R>;
readonly min: number;
readonly max: number;
readonly concurrency?: number | undefined;
readonly targetUtilization?: number | undefined;
readonly strategy: Strategy<A, E>;
}): Effect.Effect<Pool<A, E>, never, Scope.Scope | R>
A, function (type parameter) E in <A, E, R>(options: {
readonly acquire: Effect.Effect<A, E, R>;
readonly min: number;
readonly max: number;
readonly concurrency?: number | undefined;
readonly targetUtilization?: number | undefined;
readonly strategy: Strategy<A, E>;
}): Effect.Effect<Pool<A, E>, never, Scope.Scope | R>
E>
}): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<interface Pool<in out A, in out E = never>A Pool<A, E> is a pool of items of type A, each of which may be
associated with the acquisition and release of resources. An attempt to get
an item A from a pool may fail with an error of type E.
When to use
Use when you need to share a bounded set of scoped resources across fibers
while the pool manages acquisition, reuse, and release.
Pool<function (type parameter) A in <A, E, R>(options: {
readonly acquire: Effect.Effect<A, E, R>;
readonly min: number;
readonly max: number;
readonly concurrency?: number | undefined;
readonly targetUtilization?: number | undefined;
readonly strategy: Strategy<A, E>;
}): Effect.Effect<Pool<A, E>, never, Scope.Scope | R>
A, function (type parameter) E in <A, E, R>(options: {
readonly acquire: Effect.Effect<A, E, R>;
readonly min: number;
readonly max: number;
readonly concurrency?: number | undefined;
readonly targetUtilization?: number | undefined;
readonly strategy: Strategy<A, E>;
}): Effect.Effect<Pool<A, E>, never, Scope.Scope | R>
E>, never, import ScopeScope.Scope | function (type parameter) R in <A, E, R>(options: {
readonly acquire: Effect.Effect<A, E, R>;
readonly min: number;
readonly max: number;
readonly concurrency?: number | undefined;
readonly targetUtilization?: number | undefined;
readonly strategy: Strategy<A, E>;
}): Effect.Effect<Pool<A, E>, never, Scope.Scope | R>
R> =>
import EffectEffect.uninterruptibleMask(import EffectEffect.fnUntraced(function*(restore: <AX, EX, RX>(
effect: Effect<AX, EX, RX>
) => Effect<AX, EX, RX>
restore) {
const const services: Context.Context<
Scope.Scope | R
>
const services: {
mapUnsafe: ReadonlyMap<string, any>;
mutable: boolean;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
services = yield* import EffectEffect.context<function (type parameter) R in <A, E, R>(options: {
readonly acquire: Effect.Effect<A, E, R>;
readonly min: number;
readonly max: number;
readonly concurrency?: number | undefined;
readonly targetUtilization?: number | undefined;
readonly strategy: Strategy<A, E>;
}): Effect.Effect<Pool<A, E>, never, Scope.Scope | R>
R | import ScopeScope.Scope>()
const const scope: Scope.Scopeconst scope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
scope = import ContextContext.get(const services: Context.Context<
Scope.Scope | R
>
const services: {
mapUnsafe: ReadonlyMap<string, any>;
mutable: boolean;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
services, import ScopeScope.const Scope: Context.Service<Scope, Scope>const Scope: {
key: string;
Service: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
};
of: (this: void, self: Scope.Scope) => Scope.Scope;
context: (self: Scope.Scope) => Context.Context<Scope.Scope>;
use: (f: (service: Scope.Scope) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, Scope.Scope | R>;
useSync: (f: (service: Scope.Scope) => A) => Effect.Effect<A, never, Scope.Scope>;
Identifier: Identifier;
stack: string | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
A Scope represents a context where resources can be acquired and
automatically cleaned up when the scope is closed. Scopes can use
either sequential or parallel finalization strategies.
Example (Managing scoped resources)
import { Effect, Exit, Scope } from "effect"
const program = Effect.gen(function*() {
const scope = yield* Scope.make("sequential")
// Scope has a strategy and state
console.log(scope.strategy) // "sequential"
console.log(scope.state._tag) // "Open"
// Close the scope
yield* Scope.close(scope, Exit.void)
console.log(scope.state._tag) // "Closed"
})
Service tag for the active resource lifetime.
When to use
Use to access the active lifetime when registering finalizers or sharing
resources with the surrounding scope.
Example (Accessing the scope service)
import { Effect, Scope } from "effect"
const program = Effect.gen(function*() {
// Access the scope from the context
const scope = yield* Scope.Scope
// Use the scope for resource management
yield* Scope.addFinalizer(scope, Effect.log("Cleanup"))
})
// Provide a scope to the program
const scoped = Effect.scoped(program)
Scope)
const const acquire: Effect.Effect<
A,
E,
Scope.Scope
>
const acquire: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
acquire = import EffectEffect.updateContext(
options: {
readonly acquire: Effect.Effect<A, E, R>
readonly min: number
readonly max: number
readonly concurrency?: number | undefined
readonly targetUtilization?: number | undefined
readonly strategy: Strategy<A, E>
}
options.acquire: Effect.Effect<A, E, R>(property) acquire: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
acquire,
(input: Context.Context<Scope.Scope>(parameter) input: {
mapUnsafe: ReadonlyMap<string, any>;
mutable: boolean;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
input) => import ContextContext.merge(const services: Context.Context<
Scope.Scope | R
>
const services: {
mapUnsafe: ReadonlyMap<string, any>;
mutable: boolean;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
services, input: Context.Context<Scope.Scope>(parameter) input: {
mapUnsafe: ReadonlyMap<string, any>;
mutable: boolean;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
input)
) as import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<function (type parameter) A in <A, E, R>(options: {
readonly acquire: Effect.Effect<A, E, R>;
readonly min: number;
readonly max: number;
readonly concurrency?: number | undefined;
readonly targetUtilization?: number | undefined;
readonly strategy: Strategy<A, E>;
}): Effect.Effect<Pool<A, E>, never, Scope.Scope | R>
A, function (type parameter) E in <A, E, R>(options: {
readonly acquire: Effect.Effect<A, E, R>;
readonly min: number;
readonly max: number;
readonly concurrency?: number | undefined;
readonly targetUtilization?: number | undefined;
readonly strategy: Strategy<A, E>;
}): Effect.Effect<Pool<A, E>, never, Scope.Scope | R>
E, import ScopeScope.Scope>
const const concurrency: numberconcurrency = options: {
readonly acquire: Effect.Effect<A, E, R>
readonly min: number
readonly max: number
readonly concurrency?: number | undefined
readonly targetUtilization?: number | undefined
readonly strategy: Strategy<A, E>
}
options.concurrency?: number | undefinedconcurrency ?? 1
const const config: Config<A, E>const config: {
acquire: Effect.Effect<A, E, Scope.Scope>;
concurrency: number;
minSize: number;
maxSize: number;
strategy: Strategy<A, E>;
targetUtilization: number;
}
config: interface Config<A, E>Normalized configuration used by a Pool.
When to use
Use as the normalized, read-only description of how a pool acquires, sizes,
shares, and resizes its items after construction.
Details
The config stores the acquire effect, size bounds, per-item concurrency,
target utilization, and resizing strategy used by the pool implementation.
Config<function (type parameter) A in <A, E, R>(options: {
readonly acquire: Effect.Effect<A, E, R>;
readonly min: number;
readonly max: number;
readonly concurrency?: number | undefined;
readonly targetUtilization?: number | undefined;
readonly strategy: Strategy<A, E>;
}): Effect.Effect<Pool<A, E>, never, Scope.Scope | R>
A, function (type parameter) E in <A, E, R>(options: {
readonly acquire: Effect.Effect<A, E, R>;
readonly min: number;
readonly max: number;
readonly concurrency?: number | undefined;
readonly targetUtilization?: number | undefined;
readonly strategy: Strategy<A, E>;
}): Effect.Effect<Pool<A, E>, never, Scope.Scope | R>
E> = {
Config<A, E>.acquire: Effect.Effect<A, E, Scope.Scope>(property) Config<A, E>.acquire: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
acquire,
Config<A, E>.concurrency: numberconcurrency,
Config<A, E>.minSize: numberminSize: options: {
readonly acquire: Effect.Effect<A, E, R>
readonly min: number
readonly max: number
readonly concurrency?: number | undefined
readonly targetUtilization?: number | undefined
readonly strategy: Strategy<A, E>
}
options.min: numbermin,
Config<A, E>.maxSize: numbermaxSize: options: {
readonly acquire: Effect.Effect<A, E, R>
readonly min: number
readonly max: number
readonly concurrency?: number | undefined
readonly targetUtilization?: number | undefined
readonly strategy: Strategy<A, E>
}
options.max: numbermax,
Config<A, E>.strategy: Strategy<A, E>(property) Config<A, E>.strategy: {
run: (pool: Pool<A, E>) => Effect.Effect<void>;
onAcquire: (item: PoolItem<A, E>) => Effect.Effect<void>;
reclaim: (pool: Pool<A, E>) => Effect.Effect<PoolItem<A, E> | undefined>;
}
strategy: options: {
readonly acquire: Effect.Effect<A, E, R>
readonly min: number
readonly max: number
readonly concurrency?: number | undefined
readonly targetUtilization?: number | undefined
readonly strategy: Strategy<A, E>
}
options.strategy: Strategy<A, E>(property) strategy: {
run: (pool: Pool<A, E>) => Effect.Effect<void>;
onAcquire: (item: PoolItem<A, E>) => Effect.Effect<void>;
reclaim: (pool: Pool<A, E>) => Effect.Effect<PoolItem<A, E> | undefined>;
}
strategy,
Config<A, E>.targetUtilization: numbertargetUtilization: var Math: MathAn intrinsic object that provides basic mathematics functionality and constants.
Math.Math.min(...values: number[]): numberReturns the smaller of a set of supplied numeric expressions.
min(var Math: MathAn intrinsic object that provides basic mathematics functionality and constants.
Math.Math.max(...values: number[]): numberReturns the larger of a set of supplied numeric expressions.
max(options: {
readonly acquire: Effect.Effect<A, E, R>
readonly min: number
readonly max: number
readonly concurrency?: number | undefined
readonly targetUtilization?: number | undefined
readonly strategy: Strategy<A, E>
}
options.targetUtilization?: number | undefinedtargetUtilization ?? 1, 0.1), 1)
}
const const state: State<A, E>const state: {
scope: Scope.Scope;
isShuttingDown: boolean;
semaphore: Semaphore.Semaphore;
resizeSemaphore: Semaphore.Semaphore;
items: Set<PoolItem<A, E>>;
available: Set<PoolItem<A, E>>;
availableLatch: Latch.Latch;
invalidated: Set<PoolItem<A, E>>;
waiters: number;
}
state: interface State<A, E>Mutable runtime state maintained by a Pool.
When to use
Use when you need to inspect or support the runtime state backing a Pool,
including its scope, item sets, semaphores, waiters, invalidation tracking,
and shutdown flag.
Details
This state tracks the pool scope, active and available items, invalidated
items, semaphores, waiters, and shutdown status. It is exposed for
inspection and implementation support; user code should prefer the
high-level pool operations.
State<function (type parameter) A in <A, E, R>(options: {
readonly acquire: Effect.Effect<A, E, R>;
readonly min: number;
readonly max: number;
readonly concurrency?: number | undefined;
readonly targetUtilization?: number | undefined;
readonly strategy: Strategy<A, E>;
}): Effect.Effect<Pool<A, E>, never, Scope.Scope | R>
A, function (type parameter) E in <A, E, R>(options: {
readonly acquire: Effect.Effect<A, E, R>;
readonly min: number;
readonly max: number;
readonly concurrency?: number | undefined;
readonly targetUtilization?: number | undefined;
readonly strategy: Strategy<A, E>;
}): Effect.Effect<Pool<A, E>, never, Scope.Scope | R>
E> = {
State<A, E>.scope: Scope.Scope(property) State<A, E>.scope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
scope,
State<A, E>.isShuttingDown: booleanisShuttingDown: false,
State<A, E>.semaphore: Semaphore.Semaphore(property) State<A, E>.semaphore: {
resize: (this: Semaphore, permits: number) => Effect.Effect<void>;
withPermits: (this: Semaphore, permits: number) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
withPermit: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
withPermitsIfAvailable: (this: Semaphore, permits: number) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<Option.Option<A>, E, R>;
take: (this: Semaphore, permits: number) => Effect.Effect<number>;
release: (this: Semaphore, permits: number) => Effect.Effect<number>;
releaseAll: Effect.Effect<number>;
}
semaphore: import SemaphoreSemaphore.const makeUnsafe: (
permits: number
) => Semaphore
Creates a Semaphore synchronously with the specified total
number of permits.
When to use
Use to construct a semaphore synchronously when an immediate value is
required outside an Effect workflow.
Example (Creating an unsafe semaphore)
import { Effect, Semaphore } from "effect"
const semaphore = Semaphore.makeUnsafe(3)
const task = (id: number) =>
semaphore.withPermits(1)(
Effect.gen(function*() {
yield* Effect.log(`Task ${id} started`)
yield* Effect.sleep("1 second")
yield* Effect.log(`Task ${id} completed`)
})
)
// Only 3 tasks can run concurrently
const program = Effect.all([
task(1),
task(2),
task(3),
task(4),
task(5)
], { concurrency: "unbounded" })
makeUnsafe(const concurrency: numberconcurrency * options: {
readonly acquire: Effect.Effect<A, E, R>
readonly min: number
readonly max: number
readonly concurrency?: number | undefined
readonly targetUtilization?: number | undefined
readonly strategy: Strategy<A, E>
}
options.max: numbermax),
State<A, E>.resizeSemaphore: Semaphore.Semaphore(property) State<A, E>.resizeSemaphore: {
resize: (this: Semaphore, permits: number) => Effect.Effect<void>;
withPermits: (this: Semaphore, permits: number) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
withPermit: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
withPermitsIfAvailable: (this: Semaphore, permits: number) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<Option.Option<A>, E, R>;
take: (this: Semaphore, permits: number) => Effect.Effect<number>;
release: (this: Semaphore, permits: number) => Effect.Effect<number>;
releaseAll: Effect.Effect<number>;
}
resizeSemaphore: import SemaphoreSemaphore.const makeUnsafe: (
permits: number
) => Semaphore
Creates a Semaphore synchronously with the specified total
number of permits.
When to use
Use to construct a semaphore synchronously when an immediate value is
required outside an Effect workflow.
Example (Creating an unsafe semaphore)
import { Effect, Semaphore } from "effect"
const semaphore = Semaphore.makeUnsafe(3)
const task = (id: number) =>
semaphore.withPermits(1)(
Effect.gen(function*() {
yield* Effect.log(`Task ${id} started`)
yield* Effect.sleep("1 second")
yield* Effect.log(`Task ${id} completed`)
})
)
// Only 3 tasks can run concurrently
const program = Effect.all([
task(1),
task(2),
task(3),
task(4),
task(5)
], { concurrency: "unbounded" })
makeUnsafe(1),
State<A, E>.items: Set<PoolItem<A, E>>items: new var Set: SetConstructor
new <PoolItem<A, E>>(iterable?: Iterable<PoolItem<A, E>> | null | undefined) => Set<PoolItem<A, E>> (+1 overload)
Set(),
State<A, E>.available: Set<PoolItem<A, E>>available: new var Set: SetConstructor
new <PoolItem<A, E>>(iterable?: Iterable<PoolItem<A, E>> | null | undefined) => Set<PoolItem<A, E>> (+1 overload)
Set(),
State<A, E>.availableLatch: Latch.Latch(property) State<A, E>.availableLatch: {
open: Effect.Effect<boolean>;
openUnsafe: (this: Latch) => boolean;
release: Effect.Effect<boolean>;
await: Effect.Effect<void>;
close: Effect.Effect<boolean>;
closeUnsafe: (this: Latch) => boolean;
whenOpen: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
isOpen: (this: Latch) => boolean;
}
availableLatch: import LatchLatch.makeUnsafe(false),
State<A, E>.invalidated: Set<PoolItem<A, E>>invalidated: new var Set: SetConstructor
new <PoolItem<A, E>>(iterable?: Iterable<PoolItem<A, E>> | null | undefined) => Set<PoolItem<A, E>> (+1 overload)
Set(),
State<A, E>.waiters: numberwaiters: 0
}
const const self: Pool<A, E>const self: {
config: Config<A, E>;
state: State<A, E>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self: interface Pool<in out A, in out E = never>A Pool<A, E> is a pool of items of type A, each of which may be
associated with the acquisition and release of resources. An attempt to get
an item A from a pool may fail with an error of type E.
When to use
Use when you need to share a bounded set of scoped resources across fibers
while the pool manages acquisition, reuse, and release.
Pool<function (type parameter) A in <A, E, R>(options: {
readonly acquire: Effect.Effect<A, E, R>;
readonly min: number;
readonly max: number;
readonly concurrency?: number | undefined;
readonly targetUtilization?: number | undefined;
readonly strategy: Strategy<A, E>;
}): Effect.Effect<Pool<A, E>, never, Scope.Scope | R>
A, function (type parameter) E in <A, E, R>(options: {
readonly acquire: Effect.Effect<A, E, R>;
readonly min: number;
readonly max: number;
readonly concurrency?: number | undefined;
readonly targetUtilization?: number | undefined;
readonly strategy: Strategy<A, E>;
}): Effect.Effect<Pool<A, E>, never, Scope.Scope | R>
E> = {
[const TypeId: "~effect/Pool"TypeId]: const TypeId: "~effect/Pool"TypeId,
Pool<A, E>.config: Config<A, E>(property) Pool<A, E>.config: {
acquire: Effect.Effect<A, E, Scope.Scope>;
concurrency: number;
minSize: number;
maxSize: number;
strategy: Strategy<A, E>;
targetUtilization: number;
}
config,
Pool<A, E>.state: State<A, E>(property) Pool<A, E>.state: {
scope: Scope.Scope;
isShuttingDown: boolean;
semaphore: Semaphore.Semaphore;
resizeSemaphore: Semaphore.Semaphore;
items: Set<PoolItem<A, E>>;
available: Set<PoolItem<A, E>>;
availableLatch: Latch.Latch;
invalidated: Set<PoolItem<A, E>>;
waiters: number;
}
state,
function pipe(): anypipe() {
return import pipeArgumentspipeArguments(this, function (local var) arguments: IArgumentsarguments)
}
}
yield* import ScopeScope.const addFinalizer: (
scope: Scope,
finalizer: Effect<unknown>
) => Effect<void>
Registers a finalizer effect on a scope.
Details
If the scope is open, the finalizer runs when the scope closes, regardless of
whether the scope closes successfully or with an error. If the scope is
already closed, the finalizer runs immediately.
Example (Adding finalizers)
import { Console, Effect, Exit, Scope } from "effect"
const program = Effect.gen(function*() {
const scope = yield* Scope.make()
// Add simple finalizers
yield* Scope.addFinalizer(scope, Console.log("Cleanup task 1"))
yield* Scope.addFinalizer(scope, Console.log("Cleanup task 2"))
yield* Scope.addFinalizer(scope, Effect.log("Cleanup task 3"))
// Do some work
yield* Console.log("Doing work...")
// Close the scope
yield* Scope.close(scope, Exit.void)
})
addFinalizer(const scope: Scope.Scopeconst scope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
scope, const shutdown: anyshutdown(const self: Pool<A, E>const self: {
config: Config<A, E>;
state: State<A, E>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self))
yield* import EffectEffect.tap(
import EffectEffect.forkDetach(restore: <AX, EX, RX>(
effect: Effect<AX, EX, RX>
) => Effect<AX, EX, RX>
restore(const resize: <A, E>(
self: Pool<A, E>
) => Effect.Effect<void>
resize(const self: Pool<A, E>const self: {
config: Config<A, E>;
state: State<A, E>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self))),
(fiber: Fiber.Fiber<void, never>(parameter) fiber: {
id: number;
currentOpCount: number;
getRef: <A>(ref: Context.Reference<A>) => A;
context: Context.Context<never>;
setContext: (context: Context.Context<never>) => void;
currentScheduler: Scheduler;
currentDispatcher: SchedulerDispatcher;
currentSpan: AnySpan | undefined;
currentLogLevel: LogLevel;
minimumLogLevel: LogLevel;
currentStackFrame: StackFrame | undefined;
maxOpsBeforeYield: number;
currentPreventYield: boolean;
addObserver: (cb: (exit: Exit<A, E>) => void) => () => void;
interruptUnsafe: (fiberId?: number | undefined, annotations?: Context.Context<never> | undefined) => void;
pollUnsafe: () => Exit<A, E> | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
fiber) => import ScopeScope.const addFinalizer: (
scope: Scope,
finalizer: Effect<unknown>
) => Effect<void>
Registers a finalizer effect on a scope.
Details
If the scope is open, the finalizer runs when the scope closes, regardless of
whether the scope closes successfully or with an error. If the scope is
already closed, the finalizer runs immediately.
Example (Adding finalizers)
import { Console, Effect, Exit, Scope } from "effect"
const program = Effect.gen(function*() {
const scope = yield* Scope.make()
// Add simple finalizers
yield* Scope.addFinalizer(scope, Console.log("Cleanup task 1"))
yield* Scope.addFinalizer(scope, Console.log("Cleanup task 2"))
yield* Scope.addFinalizer(scope, Effect.log("Cleanup task 3"))
// Do some work
yield* Console.log("Doing work...")
// Close the scope
yield* Scope.close(scope, Exit.void)
})
addFinalizer(const scope: Scope.Scopeconst scope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
scope, import FiberFiber.interrupt(fiber: Fiber.Fiber<void, never>(parameter) fiber: {
id: number;
currentOpCount: number;
getRef: <A>(ref: Context.Reference<A>) => A;
context: Context.Context<never>;
setContext: (context: Context.Context<never>) => void;
currentScheduler: Scheduler;
currentDispatcher: SchedulerDispatcher;
currentSpan: AnySpan | undefined;
currentLogLevel: LogLevel;
minimumLogLevel: LogLevel;
currentStackFrame: StackFrame | undefined;
maxOpsBeforeYield: number;
currentPreventYield: boolean;
addObserver: (cb: (exit: Exit<A, E>) => void) => () => void;
interruptUnsafe: (fiberId?: number | undefined, annotations?: Context.Context<never> | undefined) => void;
pollUnsafe: () => Exit<A, E> | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
fiber))
)
yield* import EffectEffect.tap(
import EffectEffect.forkDetach(restore: <AX, EX, RX>(
effect: Effect<AX, EX, RX>
) => Effect<AX, EX, RX>
restore(options: {
readonly acquire: Effect.Effect<A, E, R>
readonly min: number
readonly max: number
readonly concurrency?: number | undefined
readonly targetUtilization?: number | undefined
readonly strategy: Strategy<A, E>
}
options.strategy: Strategy<A, E>(property) strategy: {
run: (pool: Pool<A, E>) => Effect.Effect<void>;
onAcquire: (item: PoolItem<A, E>) => Effect.Effect<void>;
reclaim: (pool: Pool<A, E>) => Effect.Effect<PoolItem<A, E> | undefined>;
}
strategy.Strategy<A, E>.run: (pool: Pool<A, E>) => Effect.Effect<void>run(const self: Pool<A, E>const self: {
config: Config<A, E>;
state: State<A, E>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self))),
(fiber: Fiber.Fiber<void, never>(parameter) fiber: {
id: number;
currentOpCount: number;
getRef: <A>(ref: Context.Reference<A>) => A;
context: Context.Context<never>;
setContext: (context: Context.Context<never>) => void;
currentScheduler: Scheduler;
currentDispatcher: SchedulerDispatcher;
currentSpan: AnySpan | undefined;
currentLogLevel: LogLevel;
minimumLogLevel: LogLevel;
currentStackFrame: StackFrame | undefined;
maxOpsBeforeYield: number;
currentPreventYield: boolean;
addObserver: (cb: (exit: Exit<A, E>) => void) => () => void;
interruptUnsafe: (fiberId?: number | undefined, annotations?: Context.Context<never> | undefined) => void;
pollUnsafe: () => Exit<A, E> | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
fiber) => import ScopeScope.const addFinalizer: (
scope: Scope,
finalizer: Effect<unknown>
) => Effect<void>
Registers a finalizer effect on a scope.
Details
If the scope is open, the finalizer runs when the scope closes, regardless of
whether the scope closes successfully or with an error. If the scope is
already closed, the finalizer runs immediately.
Example (Adding finalizers)
import { Console, Effect, Exit, Scope } from "effect"
const program = Effect.gen(function*() {
const scope = yield* Scope.make()
// Add simple finalizers
yield* Scope.addFinalizer(scope, Console.log("Cleanup task 1"))
yield* Scope.addFinalizer(scope, Console.log("Cleanup task 2"))
yield* Scope.addFinalizer(scope, Effect.log("Cleanup task 3"))
// Do some work
yield* Console.log("Doing work...")
// Close the scope
yield* Scope.close(scope, Exit.void)
})
addFinalizer(const scope: Scope.Scopeconst scope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
scope, import FiberFiber.interrupt(fiber: Fiber.Fiber<void, never>(parameter) fiber: {
id: number;
currentOpCount: number;
getRef: <A>(ref: Context.Reference<A>) => A;
context: Context.Context<never>;
setContext: (context: Context.Context<never>) => void;
currentScheduler: Scheduler;
currentDispatcher: SchedulerDispatcher;
currentSpan: AnySpan | undefined;
currentLogLevel: LogLevel;
minimumLogLevel: LogLevel;
currentStackFrame: StackFrame | undefined;
maxOpsBeforeYield: number;
currentPreventYield: boolean;
addObserver: (cb: (exit: Exit<A, E>) => void) => () => void;
interruptUnsafe: (fiberId?: number | undefined, annotations?: Context.Context<never> | undefined) => void;
pollUnsafe: () => Exit<A, E> | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
fiber))
)
return const self: Pool<A, E>const self: {
config: Config<A, E>;
state: State<A, E>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self
}))