<K>(key: K): <A, E>(
self: RcMap<K, A, E>
) => Effect.Effect<A, E, Scope.Scope>
<K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<A, E, Scope.Scope>Gets the resource for a key, acquiring it with the map's lookup function when the key is not already cached.
When to use
Use to acquire or retain the resource for a key within the current scope.
Details
The resource's reference count is incremented for the current Scope, and a
release finalizer is added to that scope. When the current scope closes, the
reference is released; the resource is closed when the last reference is
released, subject to the map's idle time-to-live setting.
Example (Acquiring a resource)
import { Effect, RcMap } from "effect"
Effect.gen(function*() {
const map = yield* RcMap.make({
lookup: (key: string) =>
Effect.acquireRelease(
Effect.succeed(`Resource: ${key}`),
() => Effect.log(`Released ${key}`)
)
})
// Get a resource - it will be acquired on first access
const resource = yield* RcMap.get(map, "database")
console.log(resource) // "Resource: database"
}).pipe(Effect.scoped)export const const get: {
<K>(key: K): <A, E>(
self: RcMap<K, A, E>
) => Effect.Effect<A, E, Scope.Scope>
<K, A, E>(
self: RcMap<K, A, E>,
key: K
): Effect.Effect<A, E, Scope.Scope>
}
Gets the resource for a key, acquiring it with the map's lookup function when
the key is not already cached.
When to use
Use to acquire or retain the resource for a key within the current scope.
Details
The resource's reference count is incremented for the current Scope, and a
release finalizer is added to that scope. When the current scope closes, the
reference is released; the resource is closed when the last reference is
released, subject to the map's idle time-to-live setting.
Example (Acquiring a resource)
import { Effect, RcMap } from "effect"
Effect.gen(function*() {
const map = yield* RcMap.make({
lookup: (key: string) =>
Effect.acquireRelease(
Effect.succeed(`Resource: ${key}`),
() => Effect.log(`Released ${key}`)
)
})
// Get a resource - it will be acquired on first access
const resource = yield* RcMap.get(map, "database")
console.log(resource) // "Resource: database"
}).pipe(Effect.scoped)
get: {
<function (type parameter) K in <K>(key: K): <A, E>(self: RcMap<K, A, E>) => Effect.Effect<A, E, Scope.Scope>K>(key: Kkey: function (type parameter) K in <K>(key: K): <A, E>(self: RcMap<K, A, E>) => Effect.Effect<A, E, Scope.Scope>K): <function (type parameter) A in <A, E>(self: RcMap<K, A, E>): Effect.Effect<A, E, Scope.Scope>A, function (type parameter) E in <A, E>(self: RcMap<K, A, E>): Effect.Effect<A, E, Scope.Scope>E>(self: RcMap<K, A, E>(parameter) self: {
lookup: (key: K) => Effect.Effect<A, E, Scope.Scope>;
context: Context.Context<never>;
scope: Scope.Scope;
idleTimeToLive: (key: K) => Duration.Duration;
capacity: number;
state: State<K, 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 RcMap<in out K, in out A, in out E = never>An RcMap is a reference-counted map data structure that manages the lifecycle
of resources indexed by keys. Resources are lazily acquired and automatically
released when no longer in use.
When to use
Use to share scoped resources by key while automatically releasing them after
their last active reference is gone.
Example (Inspecting a reference-counted map)
import { Effect, RcMap } from "effect"
Effect.gen(function*() {
// Create an RcMap that manages database connections
const dbConnectionMap = yield* RcMap.make({
lookup: (dbName: string) =>
Effect.acquireRelease(
Effect.succeed(`Connection to ${dbName}`),
(conn) => Effect.log(`Closing ${conn}`)
),
capacity: 10,
idleTimeToLive: "5 minutes"
})
// The RcMap interface provides access to:
// - lookup: Function to acquire resources
// - capacity: Maximum number of resources
// - idleTimeToLive: Time before idle resources are released
// - state: Current state of the map
console.log(`Capacity: ${dbConnectionMap.capacity}`)
}).pipe(Effect.scoped)
RcMap<function (type parameter) K in <K>(key: K): <A, E>(self: RcMap<K, A, E>) => Effect.Effect<A, E, Scope.Scope>K, function (type parameter) A in <A, E>(self: RcMap<K, A, E>): Effect.Effect<A, E, Scope.Scope>A, function (type parameter) E in <A, E>(self: RcMap<K, A, E>): Effect.Effect<A, E, Scope.Scope>E>) => import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<function (type parameter) A in <A, E>(self: RcMap<K, A, E>): Effect.Effect<A, E, Scope.Scope>A, function (type parameter) E in <A, E>(self: RcMap<K, A, E>): Effect.Effect<A, E, Scope.Scope>E, import ScopeScope.Scope>
<function (type parameter) K in <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<A, E, Scope.Scope>K, function (type parameter) A in <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<A, E, Scope.Scope>A, function (type parameter) E in <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<A, E, Scope.Scope>E>(self: RcMap<K, A, E>(parameter) self: {
lookup: (key: K) => Effect.Effect<A, E, Scope.Scope>;
context: Context.Context<never>;
scope: Scope.Scope;
idleTimeToLive: (key: K) => Duration.Duration;
capacity: number;
state: State<K, 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 RcMap<in out K, in out A, in out E = never>An RcMap is a reference-counted map data structure that manages the lifecycle
of resources indexed by keys. Resources are lazily acquired and automatically
released when no longer in use.
When to use
Use to share scoped resources by key while automatically releasing them after
their last active reference is gone.
Example (Inspecting a reference-counted map)
import { Effect, RcMap } from "effect"
Effect.gen(function*() {
// Create an RcMap that manages database connections
const dbConnectionMap = yield* RcMap.make({
lookup: (dbName: string) =>
Effect.acquireRelease(
Effect.succeed(`Connection to ${dbName}`),
(conn) => Effect.log(`Closing ${conn}`)
),
capacity: 10,
idleTimeToLive: "5 minutes"
})
// The RcMap interface provides access to:
// - lookup: Function to acquire resources
// - capacity: Maximum number of resources
// - idleTimeToLive: Time before idle resources are released
// - state: Current state of the map
console.log(`Capacity: ${dbConnectionMap.capacity}`)
}).pipe(Effect.scoped)
RcMap<function (type parameter) K in <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<A, E, Scope.Scope>K, function (type parameter) A in <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<A, E, Scope.Scope>A, function (type parameter) E in <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<A, E, Scope.Scope>E>, key: Kkey: function (type parameter) K in <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<A, E, Scope.Scope>K): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<function (type parameter) A in <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<A, E, Scope.Scope>A, function (type parameter) E in <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<A, E, Scope.Scope>E, import ScopeScope.Scope>
} = import dualdual(
2,
<function (type parameter) K in <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<A, E, Scope.Scope>K, function (type parameter) A in <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<A, E, Scope.Scope>A, function (type parameter) E in <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<A, E, Scope.Scope>E>(self: RcMap<K, A, E>(parameter) self: {
lookup: (key: K) => Effect.Effect<A, E, Scope.Scope>;
context: Context.Context<never>;
scope: Scope.Scope;
idleTimeToLive: (key: K) => Duration.Duration;
capacity: number;
state: State<K, 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 RcMap<in out K, in out A, in out E = never>An RcMap is a reference-counted map data structure that manages the lifecycle
of resources indexed by keys. Resources are lazily acquired and automatically
released when no longer in use.
When to use
Use to share scoped resources by key while automatically releasing them after
their last active reference is gone.
Example (Inspecting a reference-counted map)
import { Effect, RcMap } from "effect"
Effect.gen(function*() {
// Create an RcMap that manages database connections
const dbConnectionMap = yield* RcMap.make({
lookup: (dbName: string) =>
Effect.acquireRelease(
Effect.succeed(`Connection to ${dbName}`),
(conn) => Effect.log(`Closing ${conn}`)
),
capacity: 10,
idleTimeToLive: "5 minutes"
})
// The RcMap interface provides access to:
// - lookup: Function to acquire resources
// - capacity: Maximum number of resources
// - idleTimeToLive: Time before idle resources are released
// - state: Current state of the map
console.log(`Capacity: ${dbConnectionMap.capacity}`)
}).pipe(Effect.scoped)
RcMap<function (type parameter) K in <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<A, E, Scope.Scope>K, function (type parameter) A in <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<A, E, Scope.Scope>A, function (type parameter) E in <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<A, E, Scope.Scope>E>, key: Kkey: function (type parameter) K in <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<A, E, Scope.Scope>K): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<function (type parameter) A in <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<A, E, Scope.Scope>A, function (type parameter) E in <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<A, E, Scope.Scope>E, import ScopeScope.Scope> =>
import EffectEffect.uninterruptibleMask((restore: <AX, EX, RX>(
effect: Effect<AX, EX, RX>
) => Effect<AX, EX, RX>
restore) => {
if (self: RcMap<K, A, E>(parameter) self: {
lookup: (key: K) => Effect.Effect<A, E, Scope.Scope>;
context: Context.Context<never>;
scope: Scope.Scope;
idleTimeToLive: (key: K) => Duration.Duration;
capacity: number;
state: State<K, 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.RcMap<K, A, E>.state: State<K, A, E>state._tag: "Open" | "Closed"_tag === "Closed") {
return import EffectEffect.interrupt
}
const const state: State.Open<K, A, E>const state: {
_tag: "Open";
map: MutableHashMap.MutableHashMap<K, Entry<A, E>>;
}
state = self: RcMap<K, A, E>(parameter) self: {
lookup: (key: K) => Effect.Effect<A, E, Scope.Scope>;
context: Context.Context<never>;
scope: Scope.Scope;
idleTimeToLive: (key: K) => Duration.Duration;
capacity: number;
state: State<K, 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.RcMap<K, A, E>.state: State<K, A, E>(property) RcMap<K, A, E>.state: {
_tag: "Open";
map: MutableHashMap.MutableHashMap<K, Entry<A, E>>;
}
state
const const parent: Fiber.Fiber<any, any>const parent: {
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; <…;
}
parent = import FiberFiber.getCurrent()!
const const o: Option<State.Entry<A, E>>o = import MutableHashMapMutableHashMap.get(const state: State.Open<K, A, E>const state: {
_tag: "Open";
map: MutableHashMap.MutableHashMap<K, Entry<A, E>>;
}
state.State<K, A, E>.Open<K, A, E>.map: MutableHashMap.MutableHashMap<K, Entry<A, E>>(property) State<K, A, E>.Open<K, A, E>.map: {
backing: Map<K, V>;
buckets: Map<number, NonEmptyArray<K>>;
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;
}
map, key: Kkey)
let let entry: State.Entry<A, E>let entry: {
deferred: Deferred.Deferred<A, E>;
scope: Scope.Closeable;
finalizer: Effect.Effect<void>;
idleTimeToLive: Duration.Duration;
fiber: Fiber.Fiber<void> | undefined;
expiresAt: number;
refCount: number;
}
entry: State.interface State<K, A, E>.Entry<A, E>Represents an individual entry in the RcMap, containing the resource's
metadata including reference count, expiration time, and lifecycle management.
When to use
Use when inspecting the stored resource, reference count, and idle lifecycle
metadata for a single key.
Entry<function (type parameter) A in <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<A, E, Scope.Scope>A, function (type parameter) E in <K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<A, E, Scope.Scope>E>
if (const o: Option<State.Entry<A, E>>o._tag === "Some") {
let entry: State.Entry<A, E>let entry: {
deferred: Deferred.Deferred<A, E>;
scope: Scope.Closeable;
finalizer: Effect.Effect<void>;
idleTimeToLive: Duration.Duration;
fiber: Fiber.Fiber<void> | undefined;
expiresAt: number;
refCount: number;
}
entry = const o: Some<State.Entry<A, E>>const o: {
_tag: "Some";
_op: "Some";
value: A;
valueOrUndefined: A;
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;
}
o.value
let entry: State.Entry<A, E>let entry: {
deferred: Deferred.Deferred<A, E>;
scope: Scope.Closeable;
finalizer: Effect.Effect<void>;
idleTimeToLive: Duration.Duration;
fiber: Fiber.Fiber<void> | undefined;
expiresAt: number;
refCount: number;
}
entry.State<K, A, E>.Entry<A, E>.refCount: numberrefCount++
} else if (var Number: NumberConstructorAn object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers.
Number.NumberConstructor.isFinite(number: unknown): booleanReturns true if passed value is finite.
Unlike the global isFinite, Number.isFinite doesn't forcibly convert the parameter to a
number. Only finite values of the type number, result in true.
isFinite(self: RcMap<K, A, E>(parameter) self: {
lookup: (key: K) => Effect.Effect<A, E, Scope.Scope>;
context: Context.Context<never>;
scope: Scope.Scope;
idleTimeToLive: (key: K) => Duration.Duration;
capacity: number;
state: State<K, 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.RcMap<in out K, in out A, in out E = never>.capacity: numbercapacity) && import MutableHashMapMutableHashMap.size(self: RcMap<K, A, E>(parameter) self: {
lookup: (key: K) => Effect.Effect<A, E, Scope.Scope>;
context: Context.Context<never>;
scope: Scope.Scope;
idleTimeToLive: (key: K) => Duration.Duration;
capacity: number;
state: State<K, 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.RcMap<K, A, E>.state: State<K, A, E>(property) RcMap<K, A, E>.state: {
_tag: "Open";
map: MutableHashMap.MutableHashMap<K, Entry<A, E>>;
}
state.State<K, A, E>.Open<K, A, E>.map: MutableHashMap.MutableHashMap<K, Entry<A, E>>(property) State<K, A, E>.Open<K, A, E>.map: {
backing: Map<K, V>;
buckets: Map<number, NonEmptyArray<K>>;
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;
}
map) >= self: RcMap<K, A, E>(parameter) self: {
lookup: (key: K) => Effect.Effect<A, E, Scope.Scope>;
context: Context.Context<never>;
scope: Scope.Scope;
idleTimeToLive: (key: K) => Duration.Duration;
capacity: number;
state: State<K, 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.RcMap<in out K, in out A, in out E = never>.capacity: numbercapacity) {
return import EffectEffect.fail(
new import CauseCause.ExceededCapacityError(`RcMap attempted to exceed capacity of ${self: RcMap<K, A, E>(parameter) self: {
lookup: (key: K) => Effect.Effect<A, E, Scope.Scope>;
context: Context.Context<never>;
scope: Scope.Scope;
idleTimeToLive: (key: K) => Duration.Duration;
capacity: number;
state: State<K, 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.RcMap<in out K, in out A, in out E = never>.capacity: numbercapacity}`)
) as import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<never>
} else {
let entry: State.Entry<A, E>let entry: {
deferred: Deferred.Deferred<A, E>;
scope: Scope.Closeable;
finalizer: Effect.Effect<void>;
idleTimeToLive: Duration.Duration;
fiber: Fiber.Fiber<void> | undefined;
expiresAt: number;
refCount: number;
}
entry = {
State<K, A, E>.Entry<A, E>.deferred: Deferred.Deferred<A, E>(property) State<K, A, E>.Entry<A, E>.deferred: {
effect: Effect<A, E>;
resumes: Array<(effect: Effect<A, E>) => void> | 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; <…;
}
deferred: import DeferredDeferred.makeUnsafe(),
State<K, A, E>.Entry<A, E>.scope: Scope.Closeable(property) State<K, A, E>.Entry<A, E>.scope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
scope: import ScopeScope.const makeUnsafe: (
finalizerStrategy?: "sequential" | "parallel"
) => Closeable
Creates a new Scope synchronously without wrapping it in an Effect.
This is useful when you need a scope immediately but should be used with caution
as it doesn't provide the same safety guarantees as the Effect-wrapped version.
When to use
Use when a scope must be allocated synchronously and the caller will close it
manually.
Example (Creating a scope synchronously)
import { Console, Effect, Exit, Scope } from "effect"
// Create a scope immediately
const scope = Scope.makeUnsafe("sequential")
// Use it in an Effect program
const program = Effect.gen(function*() {
yield* Scope.addFinalizer(scope, Console.log("Cleanup"))
yield* Scope.close(scope, Exit.void)
})
makeUnsafe(),
State<K, A, E>.Entry<A, E>.idleTimeToLive: Duration.Duration(property) State<K, A, E>.Entry<A, E>.idleTimeToLive: {
value: DurationValue;
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;
}
idleTimeToLive: self: RcMap<K, A, E>(parameter) self: {
lookup: (key: K) => Effect.Effect<A, E, Scope.Scope>;
context: Context.Context<never>;
scope: Scope.Scope;
idleTimeToLive: (key: K) => Duration.Duration;
capacity: number;
state: State<K, 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.RcMap<K, A, E>.idleTimeToLive: (key: K) => Duration.DurationidleTimeToLive(key: Kkey),
State<K, A, E>.Entry<A, E>.finalizer: Effect.Effect<void>finalizer: var undefinedundefined as any,
State<K, A, E>.Entry<A, E>.fiber: anyfiber: var undefinedundefined,
State<K, A, E>.Entry<A, E>.expiresAt: numberexpiresAt: 0,
State<K, A, E>.Entry<A, E>.refCount: numberrefCount: 1
}
;(let entry: State.Entry<A, E>let entry: {
deferred: Deferred.Deferred<A, E>;
scope: Scope.Closeable;
finalizer: Effect.Effect<void>;
idleTimeToLive: Duration.Duration;
fiber: Fiber.Fiber<void> | undefined;
expiresAt: number;
refCount: number;
}
entry as any).finalizer = const release: <K, A, E>(
self: RcMap<K, A, E>,
key: K,
entry: State.Entry<A, E>
) => Effect.Effect<void, never, never>
release(self: RcMap<K, A, E>(parameter) self: {
lookup: (key: K) => Effect.Effect<A, E, Scope.Scope>;
context: Context.Context<never>;
scope: Scope.Scope;
idleTimeToLive: (key: K) => Duration.Duration;
capacity: number;
state: State<K, 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, key: Kkey, let entry: State.Entry<A, E>let entry: {
deferred: Deferred.Deferred<A, E>;
scope: Scope.Closeable;
finalizer: Effect.Effect<void>;
idleTimeToLive: Duration.Duration;
fiber: Fiber.Fiber<void> | undefined;
expiresAt: number;
refCount: number;
}
entry)
import MutableHashMapMutableHashMap.set(const state: State.Open<K, A, E>const state: {
_tag: "Open";
map: MutableHashMap.MutableHashMap<K, Entry<A, E>>;
}
state.State<K, A, E>.Open<K, A, E>.map: MutableHashMap.MutableHashMap<K, Entry<A, E>>(property) State<K, A, E>.Open<K, A, E>.map: {
backing: Map<K, V>;
buckets: Map<number, NonEmptyArray<K>>;
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;
}
map, key: Kkey, let entry: State.Entry<A, E>let entry: {
deferred: Deferred.Deferred<A, E>;
scope: Scope.Closeable;
finalizer: Effect.Effect<void>;
idleTimeToLive: Duration.Duration;
fiber: Fiber.Fiber<void> | undefined;
expiresAt: number;
refCount: number;
}
entry)
const const context: Map<unknown, unknown>context = new var Map: MapConstructor
new <unknown, unknown>(iterable?: Iterable<readonly [unknown, unknown]> | null | undefined) => Map<unknown, unknown> (+3 overloads)
Map(self: RcMap<K, A, E>(parameter) self: {
lookup: (key: K) => Effect.Effect<A, E, Scope.Scope>;
context: Context.Context<never>;
scope: Scope.Scope;
idleTimeToLive: (key: K) => Duration.Duration;
capacity: number;
state: State<K, 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.RcMap<in out K, in out A, in out E = never>.context: Context.Context<never>(property) RcMap<in out K, in out A, in out E = never>.context: {
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;
}
context.mapUnsafe)
const parent: Fiber.Fiber<any, any>const parent: {
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; <…;
}
parent.context.mapUnsafe.forEach((value: anyvalue, key: anykey) => {
const context: Map<unknown, unknown>context.Map<unknown, unknown>.set(key: unknown, value: unknown): Map<unknown, unknown>Adds a new element with a specified key and value to the Map. If an element with the same key already exists, the element will be updated.
set(key: anykey, value: anyvalue)
})
const context: Map<unknown, unknown>context.Map<unknown, unknown>.set(key: unknown, value: unknown): Map<unknown, unknown>Adds a new element with a specified key and value to the Map. If an element with the same key already exists, the element will be updated.
set(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.key, let entry: State.Entry<A, E>let entry: {
deferred: Deferred.Deferred<A, E>;
scope: Scope.Closeable;
finalizer: Effect.Effect<void>;
idleTimeToLive: Duration.Duration;
fiber: Fiber.Fiber<void> | undefined;
expiresAt: number;
refCount: number;
}
entry.State<K, A, E>.Entry<A, E>.scope: Scope.Closeable(property) State<K, A, E>.Entry<A, E>.scope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
scope)
self: RcMap<K, A, E>(parameter) self: {
lookup: (key: K) => Effect.Effect<A, E, Scope.Scope>;
context: Context.Context<never>;
scope: Scope.Scope;
idleTimeToLive: (key: K) => Duration.Duration;
capacity: number;
state: State<K, 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.RcMap<K, A, E>.lookup: (key: K) => Effect.Effect<A, E, Scope.Scope>lookup(key: Kkey).pipe(
import EffectEffect.runForkWith(import ContextContext.makeUnsafe(const context: Map<unknown, unknown>context)),
import FiberFiber.runIn(let entry: State.Entry<A, E>let entry: {
deferred: Deferred.Deferred<A, E>;
scope: Scope.Closeable;
finalizer: Effect.Effect<void>;
idleTimeToLive: Duration.Duration;
fiber: Fiber.Fiber<void> | undefined;
expiresAt: number;
refCount: number;
}
entry.State<K, A, E>.Entry<A, E>.scope: Scope.Closeable(property) State<K, A, E>.Entry<A, E>.scope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
scope)
).addObserver((exit: Exit.Exit<A, E>exit) => import DeferredDeferred.doneUnsafe(let entry: State.Entry<A, E>let entry: {
deferred: Deferred.Deferred<A, E>;
scope: Scope.Closeable;
finalizer: Effect.Effect<void>;
idleTimeToLive: Duration.Duration;
fiber: Fiber.Fiber<void> | undefined;
expiresAt: number;
refCount: number;
}
entry.State<K, A, E>.Entry<A, E>.deferred: Deferred.Deferred<A, E>(property) State<K, A, E>.Entry<A, E>.deferred: {
effect: Effect<A, E>;
resumes: Array<(effect: Effect<A, E>) => void> | 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; <…;
}
deferred, exit: Exit.Exit<A, E>exit))
}
const const scope: Scope.Scopeconst scope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
scope = import ContextContext.getUnsafe(const parent: Fiber.Fiber<any, any>const parent: {
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; <…;
}
parent.context, 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)
return 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, let entry: State.Entry<A, E>let entry: {
deferred: Deferred.Deferred<A, E>;
scope: Scope.Closeable;
finalizer: Effect.Effect<void>;
idleTimeToLive: Duration.Duration;
fiber: Fiber.Fiber<void> | undefined;
expiresAt: number;
refCount: number;
}
entry.State<K, A, E>.Entry<A, E>.finalizer: Effect.Effect<void>(property) State<K, A, E>.Entry<A, E>.finalizer: {
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;
}
finalizer).pipe(
import EffectEffect.andThen(restore: <AX, EX, RX>(
effect: Effect<AX, EX, RX>
) => Effect<AX, EX, RX>
restore(import DeferredDeferred.await(let entry: State.Entry<A, E>let entry: {
deferred: Deferred.Deferred<A, E>;
scope: Scope.Closeable;
finalizer: Effect.Effect<void>;
idleTimeToLive: Duration.Duration;
fiber: Fiber.Fiber<void> | undefined;
expiresAt: number;
refCount: number;
}
entry.State<K, A, E>.Entry<A, E>.deferred: Deferred.Deferred<A, E>(property) State<K, A, E>.Entry<A, E>.deferred: {
effect: Effect<A, E>;
resumes: Array<(effect: Effect<A, E>) => void> | 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; <…;
}
deferred)))
)
})
)