State<K, A, E>Represents the internal state of an RcMap, which can be either Open (active) or Closed (shutdown and no longer accepting operations).
When to use
Use when typing code that inspects an RcMap's state field and narrows
between open and closed lifecycle states.
export type type State<K, A, E> = State.Open<K, A, E> | State.ClosedRepresents the internal state of an RcMap, which can be either Open (active)
or Closed (shutdown and no longer accepting operations).
When to use
Use when typing code that inspects an RcMap's state field and narrows
between open and closed lifecycle states.
Namespace containing the internal state types for RcMap.
When to use
Use when referring to the concrete open, closed, and entry state shapes used
by RcMap.
State<function (type parameter) K in type State<K, A, E>K, function (type parameter) A in type State<K, A, E>A, function (type parameter) E in type State<K, A, E>E> = State.interface State<K, A, E>.Open<K, A, E>Represents the open/active state of an RcMap, containing the actual
resource map that stores entries.
When to use
Use when handling an RcMap that can still accept operations and contains
stored entries.
Open<function (type parameter) K in type State<K, A, E>K, function (type parameter) A in type State<K, A, E>A, function (type parameter) E in type State<K, A, E>E> | State.interface State<K, A, E>.ClosedRepresents the closed state of an RcMap, indicating that the map has been
shut down and will no longer accept new operations.
When to use
Use when handling an RcMap after its owning scope has closed.
Closed
/**
* Namespace containing the internal state types for RcMap.
*
* **When to use**
*
* Use when referring to the concrete open, closed, and entry state shapes used
* by `RcMap`.
*
* @since 4.0.0
*/
export declare namespace State {
/**
* Represents the open/active state of an RcMap, containing the actual
* resource map that stores entries.
*
* **When to use**
*
* Use when handling an `RcMap` that can still accept operations and contains
* stored entries.
*
* @category models
* @since 4.0.0
*/
export interface interface State<K, A, E>.Open<K, A, E>Represents the open/active state of an RcMap, containing the actual
resource map that stores entries.
When to use
Use when handling an RcMap that can still accept operations and contains
stored entries.
Open<function (type parameter) K in Open<K, A, E>K, function (type parameter) A in Open<K, A, E>A, function (type parameter) E in Open<K, A, E>E> {
readonly State<K, A, E>.Open<K, A, E>._tag: "Open"_tag: "Open"
readonly 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: import MutableHashMapMutableHashMap.interface MutableHashMap<out K, out V>A mutable hash map that stores key-value pairs and supports both referential
and Effect structural equality.
When to use
Use as a mutable key-value map when in-place updates are acceptable and keys
may rely on Effect structural equality.
Details
Operations mutate the map in place. Keys that implement Equal / Hash can
be looked up structurally; other keys use normal JavaScript reference or
primitive equality.
Example (Using a mutable hash map)
import { MutableHashMap } from "effect"
// Create a mutable hash map with string keys and number values
const map: MutableHashMap.MutableHashMap<string, number> = MutableHashMap
.empty()
// Add some data
MutableHashMap.set(map, "count", 42)
MutableHashMap.set(map, "total", 100)
// Use as iterable
for (const [key, value] of map) {
console.log(`${key}: ${value}`)
}
// Output:
// count: 42
// total: 100
// Convert to array
const entries = Array.from(map)
console.log(entries) // [["count", 42], ["total", 100]]
MutableHashMap<function (type parameter) K in Open<K, A, E>K, 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 Open<K, A, E>A, function (type parameter) E in Open<K, A, E>E>>
}
/**
* Represents the closed state of an RcMap, indicating that the map has been
* shut down and will no longer accept new operations.
*
* **When to use**
*
* Use when handling an `RcMap` after its owning scope has closed.
*
* @category models
* @since 4.0.0
*/
export interface interface State<K, A, E>.ClosedRepresents the closed state of an RcMap, indicating that the map has been
shut down and will no longer accept new operations.
When to use
Use when handling an RcMap after its owning scope has closed.
Closed {
readonly State<K, A, E>.Closed._tag: "Closed"_tag: "Closed"
}
/**
* 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.
*
* @category models
* @since 4.0.0
*/
export interface 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 Entry<A, E>A, function (type parameter) E in Entry<A, E>E> {
readonly 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.interface Deferred<in out A, in out E = never>A Deferred represents an asynchronous variable that can be set exactly
once, with the ability for an arbitrary number of fibers to suspend (by
calling Deferred.await) and automatically resume when the variable is set.
When to use
Use to coordinate multiple fibers around a value or failure that will be
supplied exactly once.
Example (Creating a Deferred for inter-fiber communication)
import { Deferred, Effect, Fiber } from "effect"
// Create and use a Deferred for inter-fiber communication
const program = Effect.gen(function*() {
// Create a Deferred that will hold a string value
const deferred: Deferred.Deferred<string> = yield* Deferred.make<string>()
// Fork a fiber that will set the deferred value
const producer = yield* Effect.forkChild(
Effect.gen(function*() {
yield* Effect.sleep("100 millis")
yield* Deferred.succeed(deferred, "Hello, World!")
})
)
// Fork a fiber that will await the deferred value
const consumer = yield* Effect.forkChild(
Effect.gen(function*() {
const value = yield* Deferred.await(deferred)
console.log("Received:", value)
return value
})
)
// Wait for both fibers to complete
yield* Fiber.join(producer)
const result = yield* Fiber.join(consumer)
return result
})
Companion namespace containing type-level metadata for Deferred.
When to use
Use to reference type-level metadata associated with Deferred.
Deferred<function (type parameter) A in Entry<A, E>A, function (type parameter) E in Entry<A, E>E>
readonly 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.Closeable
readonly 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: 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<void>
readonly 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: import DurationDuration.Duration
State<K, A, E>.Entry<A, E>.fiber: Fiber.Fiber<void> | undefinedfiber: import FiberFiber.interface Fiber<out A, out E = never>A runtime fiber is a lightweight thread that executes Effects. Fibers are
the unit of concurrency in Effect. They provide a way to run multiple
Effects concurrently while maintaining structured concurrency and
cancellation safety.
When to use
Use to observe, join, interrupt, or coordinate work that has already been
forked.
Details
A fiber exposes both safe Effect-based operations, such as
await
,
join
, and
interrupt
, and low-level runtime fields used by
the scheduler and runtime internals.
Gotchas
Prefer the exported functions in this module over calling interruptUnsafe
or pollUnsafe directly. The unsafe methods are immediate runtime hooks and
do not provide the same Effect-based sequencing guarantees.
Example (Awaiting a forked fiber)
import { Effect, Fiber } from "effect"
const program = Effect.gen(function*() {
// Fork an effect to run in a new fiber
const fiber = yield* Effect.forkChild(Effect.succeed(42))
// Wait for the fiber to complete and get its result
const result = yield* Fiber.await(fiber)
console.log(result) // Exit.succeed(42)
return result
})
The Fiber namespace contains utility types and functions for working with fibers.
It provides type-level utilities for fiber operations and variance encoding.
When to use
Use to reference type-level helpers associated with Fiber.
Details
The namespace currently exposes type-level support used by the Fiber
interface. Runtime operations are exported as module-level functions.
Example (Working with fiber types)
import { Effect, Fiber } from "effect"
const program = Effect.gen(function*() {
// Create a fiber
const fiber = yield* Effect.forkChild(Effect.succeed(42))
// Use namespace types for variance
const typedFiber: Fiber.Fiber<number, never> = fiber
// Access fiber properties
console.log(`Fiber ID: ${fiber.id}`)
// Join the fiber
const result = yield* Fiber.join(fiber)
return result // 42
})
Fiber<void> | undefined
State<K, A, E>.Entry<A, E>.expiresAt: numberexpiresAt: number
State<K, A, E>.Entry<A, E>.refCount: numberrefCount: number
}
}