<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.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<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.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<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.const uninterruptibleMask: <A, E, R>(
f: (
restore: <AX, EX, RX>(
effect: Effect<AX, EX, RX>
) => Effect<AX, EX, RX>
) => Effect<A, E, R>
) => Effect<A, E, R>
Disables interruption and provides a restore function to restore the
interruptible state within the effect.
Example (Restoring interruption in protected regions)
import { Console, Effect } from "effect"
const program = Effect.uninterruptibleMask((restore) =>
Effect.gen(function*() {
yield* Console.log("Uninterruptible phase...")
yield* Effect.sleep("1 second")
// Restore interruptibility for this part
yield* restore(
Effect.gen(function*() {
yield* Console.log("Interruptible phase...")
yield* Effect.sleep("2 seconds")
})
)
yield* Console.log("Back to uninterruptible")
})
)
uninterruptibleMask(import EffectEffect.const fnUntraced: <Effect.Effect<void, never, never> | Effect.Effect<Context.Context<Scope.Scope | R>, never, Scope.Scope | R>, Pool<A, E>, [restore: <AX, EX, RX>(effect: Effect.Effect<AX, EX, RX>) => Effect.Effect<AX, EX, RX>]>(body: (this: unassigned, restore: <AX, EX, RX>(effect: Effect.Effect<AX, EX, RX>) => Effect.Effect<AX, EX, RX>) => Generator<Effect.Effect<void, never, never> | Effect.Effect<Context.Context<Scope.Scope | R>, never, Scope.Scope | R>, Pool<...>, never>) => (restore: <AX, EX, RX>(effect: Effect.Effect<AX, EX, RX>) => Effect.Effect<AX, EX, RX>) => Effect.Effect<...> (+41 overloads)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.const context: <R = never>() => Effect<
Context.Context<R>,
never,
R
>
Returns the complete context.
When to use
Use to read the complete Context available to the current effect.
Details
This function allows you to access all services that are currently available
in the effect's environment. This can be useful for debugging, introspection,
or when you need to pass the entire context to another function.
Example (Reading the full context)
import { Console, Context, Effect, Option } from "effect"
const Logger = Context.Service<{
log: (msg: string) => void
}>("Logger")
const Database = Context.Service<{
query: (sql: string) => string
}>("Database")
const program = Effect.gen(function*() {
const allServices = yield* Effect.context()
// Check if specific services are available
const loggerOption = Context.getOption(allServices, Logger)
const databaseOption = Context.getOption(allServices, Database)
yield* Console.log(`Logger available: ${Option.isSome(loggerOption)}`)
yield* Console.log(`Database available: ${Option.isSome(databaseOption)}`)
})
const context = Context.make(Logger, { log: console.log })
.pipe(Context.add(Database, { query: () => "result" }))
const provided = Effect.provideContext(program, context)
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.const get: {
<Services, I extends Services, S>(
service: Key<I, S>
): (self: Context<Services>) => S
<Services, I extends Services, S>(
self: Context<Services>,
service: Key<I, S>
): S
}
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.const updateContext: {
<R2, R>(
f: (
context: Context.Context<R2>
) => Context.Context<NoInfer<R>>
): <A, E>(
self: Effect<A, E, R>
) => Effect<A, E, R2>
<A, E, R, R2>(
self: Effect<A, E, R>,
f: (
context: Context.Context<R2>
) => Context.Context<NoInfer<R>>
): Effect<A, E, R2>
}
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.const merge: {
<R1>(that: Context<R1>): <Services>(
self: Context<Services>
) => Context<R1 | Services>
<Services, R1>(
self: Context<Services>,
that: Context<R1>
): Context<Services | R1>
}
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.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<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.const makeUnsafe: (
open?: boolean | undefined
) => Latch
Creates a Latch synchronously, outside of Effect.
When to use
Use when you need to allocate a Latch synchronously outside an Effect
workflow.
Details
The latch starts closed by default; pass true to create it open.
Example (Creating a latch unsafely)
import { Effect, Latch } from "effect"
const latch = Latch.makeUnsafe(false)
const waiter = Effect.gen(function*() {
yield* Effect.log("Waiting for latch to open...")
yield* latch.await
yield* Effect.log("Latch opened! Continuing...")
})
const opener = Effect.gen(function*() {
yield* Effect.sleep("2 seconds")
yield* Effect.log("Opening latch...")
yield* latch.open
})
const program = Effect.all([waiter, opener])
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,
Pipeable.pipe<A>(this: A): A (+21 overloads)pipe() {
return pipeArguments<Pool<A, E>>(self: Pool<A, E>, args: IArguments): unknownApplies a pipe method's variadic arguments to an initial value from left
to right.
When to use
Use to implement a custom .pipe(...) method from JavaScript's arguments
object.
Details
This helper is intended for implementing Pipeable.pipe methods that
receive JavaScript's arguments object. With no functions it returns the
original value; otherwise it feeds each result into the next function.
Example (Implementing a pipe method)
import { Pipeable } from "effect"
class NumberBox {
constructor(readonly value: number) {}
pipe(..._fns: ReadonlyArray<(value: number) => number>): number {
return Pipeable.pipeArguments(this.value, arguments) as number
}
}
const result = new NumberBox(5).pipe(
(n) => n + 2,
(n) => n * 3
)
console.log(result) // 21
pipeArguments(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: <A, E>(
self: Pool<A, E>
) => Effect.Effect<void, never, never>
shutdown(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.const tap: {
<A, B, E2, R2>(
f: (a: NoInfer<A>) => Effect<B, E2, R2>
): <E, R>(
self: Effect<A, E, R>
) => Effect<A, E | E2, R | R2>
<B, E2, R2>(f: Effect<B, E2, R2>): <A, E, R>(
self: Effect<A, E, R>
) => Effect<A, E | E2, R | R2>
<A, E, R, B, E2, R2>(
self: Effect<A, E, R>,
f: (a: NoInfer<A>) => Effect<B, E2, R2>
): Effect<A, E | E2, R | R2>
<A, E, R, B, E2, R2>(
self: Effect<A, E, R>,
f: Effect<B, E2, R2>
): Effect<A, E | E2, R | R2>
}
tap(
import EffectEffect.const forkDetach: <
Arg extends
| Effect<any, any, any>
| {
readonly startImmediately?:
| boolean
| undefined
readonly uninterruptible?:
| boolean
| "inherit"
| undefined
}
| undefined = {
readonly startImmediately?:
| boolean
| undefined
readonly uninterruptible?:
| boolean
| "inherit"
| undefined
}
>(
effectOrOptions?: Arg,
options?:
| {
readonly startImmediately?:
| boolean
| undefined
readonly uninterruptible?:
| boolean
| "inherit"
| undefined
}
| undefined
) => [Arg] extends [
Effect<infer _A, infer _E, infer _R>
]
? Effect<Fiber<_A, _E>, never, _R>
: <A, E, R>(
self: Effect<A, E, R>
) => Effect<Fiber<A, E>, never, R>
Forks the effect into a new fiber attached to the global scope. Because the
new fiber is attached to the global scope, when the fiber executing the
returned effect terminates, the forked fiber will continue running.
Example (Forking a detached fiber)
import { Effect } from "effect"
const daemonTask = Effect.gen(function*() {
while (true) {
yield* Effect.sleep("1 second")
yield* Effect.log("Daemon running...")
}
})
const program = Effect.gen(function*() {
const fiber = yield* daemonTask.pipe(Effect.forkDetach)
// or fork a fiber that starts immediately:
yield* daemonTask.pipe(Effect.forkDetach({ startImmediately: true }))
yield* Effect.log("Daemon started")
yield* Effect.sleep("3 seconds")
// Daemon continues running after this effect completes
return "main completed"
})
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.const interrupt: <A, E>(
self: Fiber<A, E>
) => Effect<void>
Interrupts a fiber, causing it to stop executing and clean up any
acquired resources.
When to use
Use when you need to cancel a forked fiber and wait for its cleanup to
complete.
Details
The returned Effect completes only after the interrupted fiber has completed.
Gotchas
Interruption is cooperative. A fiber can continue running while it is inside
uninterruptible work or finalizers.
Example (Interrupting a fiber)
import { Effect, Fiber } from "effect"
const program = Effect.gen(function*() {
const fiber = yield* Effect.forkChild(
Effect.delay("1 second")(Effect.succeed(42))
)
yield* Fiber.interrupt(fiber)
console.log("Fiber interrupted")
})
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.const tap: {
<A, B, E2, R2>(
f: (a: NoInfer<A>) => Effect<B, E2, R2>
): <E, R>(
self: Effect<A, E, R>
) => Effect<A, E | E2, R | R2>
<B, E2, R2>(f: Effect<B, E2, R2>): <A, E, R>(
self: Effect<A, E, R>
) => Effect<A, E | E2, R | R2>
<A, E, R, B, E2, R2>(
self: Effect<A, E, R>,
f: (a: NoInfer<A>) => Effect<B, E2, R2>
): Effect<A, E | E2, R | R2>
<A, E, R, B, E2, R2>(
self: Effect<A, E, R>,
f: Effect<B, E2, R2>
): Effect<A, E | E2, R | R2>
}
tap(
import EffectEffect.const forkDetach: <
Arg extends
| Effect<any, any, any>
| {
readonly startImmediately?:
| boolean
| undefined
readonly uninterruptible?:
| boolean
| "inherit"
| undefined
}
| undefined = {
readonly startImmediately?:
| boolean
| undefined
readonly uninterruptible?:
| boolean
| "inherit"
| undefined
}
>(
effectOrOptions?: Arg,
options?:
| {
readonly startImmediately?:
| boolean
| undefined
readonly uninterruptible?:
| boolean
| "inherit"
| undefined
}
| undefined
) => [Arg] extends [
Effect<infer _A, infer _E, infer _R>
]
? Effect<Fiber<_A, _E>, never, _R>
: <A, E, R>(
self: Effect<A, E, R>
) => Effect<Fiber<A, E>, never, R>
Forks the effect into a new fiber attached to the global scope. Because the
new fiber is attached to the global scope, when the fiber executing the
returned effect terminates, the forked fiber will continue running.
Example (Forking a detached fiber)
import { Effect } from "effect"
const daemonTask = Effect.gen(function*() {
while (true) {
yield* Effect.sleep("1 second")
yield* Effect.log("Daemon running...")
}
})
const program = Effect.gen(function*() {
const fiber = yield* daemonTask.pipe(Effect.forkDetach)
// or fork a fiber that starts immediately:
yield* daemonTask.pipe(Effect.forkDetach({ startImmediately: true }))
yield* Effect.log("Daemon started")
yield* Effect.sleep("3 seconds")
// Daemon continues running after this effect completes
return "main completed"
})
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.const interrupt: <A, E>(
self: Fiber<A, E>
) => Effect<void>
Interrupts a fiber, causing it to stop executing and clean up any
acquired resources.
When to use
Use when you need to cancel a forked fiber and wait for its cleanup to
complete.
Details
The returned Effect completes only after the interrupted fiber has completed.
Gotchas
Interruption is cooperative. A fiber can continue running while it is inside
uninterruptible work or finalizers.
Example (Interrupting a fiber)
import { Effect, Fiber } from "effect"
const program = Effect.gen(function*() {
const fiber = yield* Effect.forkChild(
Effect.delay("1 second")(Effect.succeed(42))
)
yield* Fiber.interrupt(fiber)
console.log("Fiber interrupted")
})
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
}))